I’m working on an FFmpeg movie writer that can also save audio, but I cannot seem to get the audio part right. The recorded length of the audio file is off.
mInputDeviceNode = ctx->createInputDeviceNode( device ); mMonitorNode = ctx->makeNode( new audio::MonitorNode() ); mInputDeviceNode >> mMonitorNode;
I get the buffer from the
MonitorNode, make it interleaved and write it to the FFmpeg pipe.
The input device parameters:
-- alsa_input.pci-0000_00_1f.3.analog-stereo -- key: alsa_input.pci-0000_00_1f.3.analog-stereo inputs: 2, outputs: 0 samplerate: 44100, frames per block: 512
FFmpeg expects 44100 sample rate, 2 channels and PCM 32-bit float little-endian audio:
ffmpeg -c:a pcm_f32le -f f32le -ar 44100 -ac 2 -i pipeaudio -vn -c:a aac -b:a 128k movie.mp4
The saved audio file is shorter and quicker than the sound recorded, although the parameters are matching.
Am I missing something about how
MonitorNode works? Any suggestions would be greatly appreciated.