0
votes

I'm working on a project that need to decode AC3 audio to PCM codec. I'm using ffmpeg - libavcodec to decode this AC3 audio but the result is always in PCM Signed 16bit Floating Point. Since I need the result to be PCM Signed 16 Bit Big Endian, what I do now is using libswscale to change it to PCM Signed `16 Bit Little Endian and encode it to PCM Signed 16 Bit Big Endian. This is not acceptable in my case since I'm working in embedded linux environment with low CPU.

Is there any way to decode audio to specific PCM codec directly, what settings I should set?

Thanks a lot guys

1

1 Answers

0
votes

It depends on the FFmpeg version you are using.

  • On very old versions, all AC3 decoding (and all audio I think) were done in SAMPLE_FMT_S16 format, so no issue for you.

  • Starting at FFmpeg version 0.7, and up to version 1.0.x, the default is still SAMPLE_FMT_S16, but you can choose to decode in floating point format (AV_SAMPLE_FMT_FLT) by changing the AVCodecContext::request_sample_fmt member.

See this code from version 0.7, in AC3 decoding initialization:

/* set scale value for float to int16 conversion */
if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) {
    s->mul_bias = 1.0f;
    avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
} else {
    s->mul_bias = 32767.0f;
    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
}
  • Beginning at version 1.1, you have no choice: decoding is done in AV_SAMPLE_FMT_FLTP format (Floating point, but planar: each channel is in its own buffer). If you want S16 data, you have to create a SwrContext and call swr_convert().

  • Last month, FFmpeg 2.3 went out. AC3 decoder was unchanged, but as you can see in their release notes, they added:

AC3 fixed-point decoding

This new decoder decodes AC3 into AV_SAMPLE_FMT_S16P format. I am not sure on how you can activate if: maybe you have to force the decoding codec, or maybe there is a .configure option (I see a lot of #if (USE_FIXED) in the source code). You may check in this direction.