audio::MonitorNode to FFmpeg

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.


Writing a node inherited from audio::SampleRecorderNode and sending the audio::Buffer data from its process() method seems to give much better results than using audio::MonitorNode.

Yea MonitorNode is meant for getting audio samples (either waveform or frequency domain) off of the audio thread and into a buffer you can use in a thread-safe manner for drawing code or some other purpose. It will skip some blocks as necessary to keep from blocking the audio thread, etc. SampleRecorderNode is pretty rudimentary but does basically what you need - writes audio from the graph into a buffer that you can then copy out.


1 Like

Thanks for the explanation.