[Libav-user] How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Suhail Doshi suhail at mightyapp.com
Fri Jan 17 09:53:06 EET 2020

I am trying to encode raw audio (pcm_f32le) to AAC encoded audio. One thing I've noticed is that I can accomplish this via the CLI tool:

ffmpeg -f f32le -ar 48000 -ac 2 -c:a pcm_f32le -i out.raw out.m4a -y

This plays just fine and decodes fine.

The steps I've taken:


When I am using the C example code: https://ffmpeg.org/doxygen/3.4/encode_audio_8c-example.html and switch the encoder to codec = avcodec_find_encoder(AV_CODEC_ID_AAC);


Output the various sample formats associated with AAC, it only provides FLTP. That assumes a planar/interleaved format.


This page ( https://forum.videohelp.com/threads/373264-FFMpeg-List-of-working-sample-formats-per-format-and-encoder ) seems to provide the various supported input formats per codec.

This is confusing because I don't think my raw captured audio is interleaved. I've certainly tried passing it through and it doesn't work as intended.

It will stay stuck here with this ret code indefinitely after calling avcodec_receive_packet :

AVERROR(EAGAIN): output is not available in the current state - user must try to send input



How can I modify the example code from FFmpeg to convert pcm_f32le raw audio to AAC encoded audio?


Why is the CLI tool able to?


I am using libsoundio ( http://libsound.io/ ) to capture raw audio from Linux's Dummy Output. I wonder how I could get a planar format to pass through to get AAC encoded audio.


If AAC is not a possibility, is doing so with MP3?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200117/8825071a/attachment.html>

More information about the Libav-user mailing list