FFmpeg在解碼小的mp3文件時凍結。 Thecrash發生在大約8或9個數據緩衝區之後。我不知道發生了什麼。Ffmpeg在解碼時死機
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();
你從哪裏得到塊大小?對於48khz單聲道PCM,ffmpeg默認顯示2048的幀大小。 – Mulvya
首先,確保您可以將所有預期的輸出寫入本地文件。如果這可行,請檢查您的管道。 –
@AlexCohn我對這個新手有一點點興趣,但是到目前爲止已經設法完成所有工作。 –