# audio::MonitorNode to FFmpeg

**URL:** <https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567>\
**Category:** Using Cinder\
**Created:** [September 20, 2019, 1:48pm UTC](https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567 "2019-09-20T13:48:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [September 20, 2019, 1:48pm UTC](https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567/1 "2019-09-20T13:48:55Z")

</div>

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.

```auto
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:

```auto
-- 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.

-Gabor

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [September 20, 2019, 4:09pm UTC](https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567/2 "2019-09-20T16:09:50Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [September 20, 2019, 11:44pm UTC](https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567/3 "2019-09-20T23:44:58Z")

</div>

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.

cheers,  
Rich

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [September 21, 2019, 5:32am UTC](https://discourse.libcinder.org/t/audio-monitornode-to-ffmpeg/1567/4 "2019-09-21T05:32:03Z")

</div>

Thanks for the explanation.
