我想记录原始音频从WASAPI回环由NAudio和管道到FFmpeg通过内存流流。从这个文档,FFmpeg可以得到输入作为原始,但我得到了8~10倍的结果速度!这是我的代码:
waveInput = new WasapiLoopbackCapture();
waveInput.DataAvailable += new EventHandler<WaveInEventArgs>((object sender, WaveInEventArgs e) =>
{
lock (e.Buffer)
{
if (waveInput == null)
return;
try
{
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
memoryStream.Write(e.Buffer, 0, e.Buffer.Length);
memoryStream.WriteTo(ffmpeg.StandardInput.BaseStream);
}
}
catch (Exception)
{
throw;
}
}
});
waveInput.StartRecording();FFmpeg参数:
ffmpegProcess.StartInfo.Arguments = String.Format("-f s16le -i pipe:0 -y output.wav");工作解决方案
waveInput = new WasapiLoopbackCapture();
waveInput.DataAvailable += new EventHandler<WaveInEventArgs>((object sender, WaveInEventArgs e) =>
{
lock (e.Buffer)
{
if (waveInput == null)
return;
try
{
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
memoryStream.Write(e.Buffer, 0, e.BytesRecorded);
memoryStream.WriteTo(ffmpeg.StandardInput.BaseStream);
}
}
catch (Exception)
{
throw;
}
}
});
waveInput.StartRecording();FFMpeg参数:
ffmpegProcess.StartInfo.Arguments = string.Format("-f f32le -ac 2 -ar 44.1k -i pipe:0 -c:a copy -y output.wav");发布于 2017-02-19 19:14:07
确保将正确的波形参数传递给FFMpeg。有关这方面的详细信息,您将检查FFmpeg文档。WASAPI捕获将是立体声IEEE浮点(32位),可能是44.1kHz或48 and。另外,您应该使用e.BytesRecorded而不是e.Buffer.Length。
发布于 2017-02-20 06:59:19
FFmpeg原始PCM音频演示程序需要提供适当数量的信道(-channels,默认值为1)和采样率(-sample_rate,默认值为44100)。
选项的顺序很重要:在紧接输入之前的选项被应用于输入,而在紧接输出之前的选项被应用于输出。
ffmpeg cli示例:
ffmpeg -f s32le -channels 2 -sample_rate 44100 -i pipe:0 -c copy output.wav您的代码示例:
ffmpegProcess.StartInfo.Arguments = String.Format("-y -f s32le -channels 2 -sample_rate 44100 -i pipe:0 -c copy output.wav");发布于 2021-04-21 13:35:45
使用WasapiLoopbackCapture,以下是在没有扭曲或减速的情况下为我工作的完整命令:
string command = $"-f f32le -channels {wasapiLoopbackCapture.WaveFormat.Channels} -sample_rate {wasapiLoopbackCapture.WaveFormat.SampleRate} -i {pipePrefix}{pipeName} ffmpegtest.wav";https://stackoverflow.com/questions/42329248
复制相似问题