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

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Suhail Doshi-2

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:

  1. 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);

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

  3. This page 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

Questions:

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

  2. Why is the CLI tool able to?

  3. I am using libsoundio 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.

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



Suhail


_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Carl Eugen Hoyos-2


Am Fr., 17. Jan. 2020 um 09:01 Uhr schrieb Suhail Doshi <[hidden email]>:

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

AV_SAMPLE_FMT_FLTP is not interleaved but a planar format.

Carl Eugen

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Suhail Doshi-2
Sure, do you know why ffmpeg cli seems to be able to encode interleaved raw audio but the C API only allows FLTP then? 

On Sun, Jan 19, 2020 at 11:48 AM Carl Eugen Hoyos <[hidden email]> wrote:


Am Fr., 17. Jan. 2020 um 09:01 Uhr schrieb Suhail Doshi <[hidden email]>:

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

AV_SAMPLE_FMT_FLTP is not interleaved but a planar format.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
--

Suhail

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Carl Eugen Hoyos-2
Am Mo., 20. Jan. 2020 um 01:22 Uhr schrieb Suhail Doshi <[hidden email]>:

> Sure, do you know why ffmpeg cli seems to be able to encode interleaved
> raw audio but the C API only allows FLTP then?

It (automatically) inserts the aresample filter into the filter chain.

Please find out what top-posting means and avoid it here, Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Suhail Doshi-2
On Sun, Jan 19, 2020 at 4:28 PM Carl Eugen Hoyos <[hidden email]> wrote:
Am Mo., 20. Jan. 2020 um 01:22 Uhr schrieb Suhail Doshi <[hidden email]>:

> Sure, do you know why ffmpeg cli seems to be able to encode interleaved
> raw audio but the C API only allows FLTP then?

It (automatically) inserts the aresample filter into the filter chain.

Please find out what top-posting means and avoid it here, Carl Eugen

Got it.  So, I tried to resample my FLT audio into FLTP audio as well. I got a bit stuck.

Here's my code: https://gist.github.com/Suhail/151e41f3eb226504c7cbd3b46c15729c (I didn't want to paste it here since it's long where I referenced this code heavily.

What I do, as a test, is I read an entire PCM raw audio file into a buffer and then send that to the encoder. While the encoder doesn't output an error, it doesn't seem to output any valid AAC encoded audio either. Even after a flush, it seems to provide a substantially small amount of information that's invalid to play.

I also tried sending it packets of raw audio captured from PulseAudio but received similar results.

Any ideas? I feel like I am missing something fundamental.

 
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Carl Eugen Hoyos-2
Am Di., 21. Jan. 2020 um 04:25 Uhr schrieb Suhail Doshi <[hidden email]>:

>
> On Sun, Jan 19, 2020 at 4:28 PM Carl Eugen Hoyos <[hidden email]> wrote:
>>
>> Am Mo., 20. Jan. 2020 um 01:22 Uhr schrieb Suhail Doshi <[hidden email]>:
>>
>> > Sure, do you know why ffmpeg cli seems to be able to encode interleaved
>> > raw audio but the C API only allows FLTP then?
>>
>> It (automatically) inserts the aresample filter into the filter chain.
>>
>> Please find out what top-posting means and avoid it here, Carl Eugen
>
>
> Got it.  So, I tried to resample my FLT audio into FLTP audio as well. I got a bit stuck.
>
> Here's my code: https://gist.github.com/Suhail/151e41f3eb226504c7cbd3b46c15729c
> (I didn't want to paste it here since it's long where I referenced this code heavily.
>
> What I do, as a test, is I read an entire PCM raw audio file into a buffer and then send that to the encoder.

Why don't you use a wav file and read that with libavformat / did you
test reading the pcm raw file with ffmpeg?

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How do you encode raw pcm_f32le audio to AAC encoded audio with FFmpeg (C/C++)?

Suhail Doshi-2

On Tue, Jan 21 2020 at 5:28 AM, <[hidden email]> wrote:

Am Di., 21. Jan. 2020 um 04:25 Uhr schrieb Suhail Doshi <[hidden email]>:
>

On Sun, Jan 19, 2020 at 4:28 PM Carl Eugen Hoyos <[hidden email]> wrote:

>>

Am Mo., 20. Jan. 2020 um 01:22 Uhr schrieb Suhail Doshi <[hidden email]>:

>>

> Sure, do you know why ffmpeg cli seems to be able to encode interleaved
> raw audio but the C API only allows FLTP then?

>>

It (automatically) inserts the aresample filter into the filter chain.

>>

Please find out what top-posting means and avoid it here, Carl Eugen

>
>

Got it. So, I tried to resample my FLT audio into FLTP audio as well. I got a bit stuck.

>

Here's my code: https://gist.github.com/Suhail/151e41f3eb226504c7cbd3b46c15729c
(I didn't want to paste it here since it's long where I referenced this code heavily.

>

What I do, as a test, is I read an entire PCM raw audio file into a buffer and then send that to the encoder.

Why don't you use a wav file and read that with libavformat / did you test reading the pcm raw file with ffmpeg?


Yes, I did this with the same file and it works as expected: ffmpeg -f f32le -ar 48000 -ac 2 -c:a pcm_f32le -i out.raw out.m4a -y

This is essentially what I am trying to write in C/C++ and then plan to make it work on streaming data.


Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".


_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".