[Libav-user] How to get raw audio frames from an audio file

Carl Eugen Hoyos ceffmpeg at gmail.com
Sat Oct 20 21:33:26 EEST 2018

2018-10-20 16:11 GMT+02:00, Finalspace <finalspace at googlemail.com>:

> the example you are following just writes the frame out in raw format,
> without doing any kind of sample rate or format conversion.
> To convert a sample you need to check against the sample format
> (dec_ctx->sample_fmt) and implement the right conversion.
> For example if your audio stream uses a sample format of S16 (Signed
> 16-bit integer), converting that to float is really easy (Just divide by
> max int16):

Note that libswresample should be able to do this conversion
significantly faster.
Also note that (just like the default decoder for a given file is not
part of the API) decoders in different versions of FFmpeg may
output different sample formats, the sample formats have
changed in the past (without much information for you) and may
change in the future: You always have to check the sample format
of the decoder in your code!

Carl Eugen

More information about the Libav-user mailing list