FFmpeg se bloque lors du décodage d'un petit fichier mp3. La fente se produit de manière cohérente après avoir introduit environ 8 ou 9 tampons de données. Je n'ai aucune idée de ce qui se passe.Ffmpeg se bloque lors du décodage
await e.Channel.SendMessage("Playing");
var server = e.Server;
var voiceChannel = client.FindServers(server.Name).FirstOrDefault().VoiceChannels.FirstOrDefault();
var _vClient = await client.GetService<AudioService>()
.Join(voiceChannel);
var pathOrUrl = "a.mp3";
var process = Process.Start(new ProcessStartInfo
{ // FFmpeg requires us to spawn a process and hook into its stdout, so we will create a Process
FileName = "ffmpeg",
Arguments = $"-i {pathOrUrl} " + // Here we provide a list of arguments to feed into FFmpeg. -i means the location of the file/URL it will read from
"-f s16le -ar 48000 -ac 1 pipe:1", // Next, we tell it to output 16-bit 48000Hz PCM, over 2 channels, to stdout.
UseShellExecute = false,
RedirectStandardOutput = true // Capture the stdout of the process
});
Thread.Sleep(2000); // Sleep for a few seconds to FFmpeg can start processing data.
int blockSize = 3840; // The size of bytes to read per frame; 1920 for mono
byte[] buffer = new byte[blockSize];
int byteCount;
while (true) // Loop forever, so data will always be read
{
byteCount = process.StandardOutput.BaseStream // Access the underlying MemoryStream from the stdout of FFmpeg
.Read(buffer, 0, blockSize); // Read stdout into the buffer
if (byteCount == 0) { // FFmpeg did not output anything
Console.WriteLine("Finished");
break;
}// Break out of the while(true) loop, since there was nothing to read.
_vClient.Send(buffer, 0, byteCount); // Send our data to Discord
}
_vClient.Wait();
D'où avez-vous obtenu le blocksize? ffmpeg me montre une taille d'image de 2048 par défaut pour PCM 48khz-mono. – Mulvya
Tout d'abord, assurez-vous que vous pouvez écrire toutes les sorties attendues dans un fichier local. Si cela fonctionne, vérifiez votre pipe. –
@AlexCohn Je suis un peu dans la tête sur celui-ci im un peu débutant mais j'ai réussi à tout arranger jusqu'ici. –