[Libav-user] AVCodecContext::request_sample_fmt is not working

Paul B Mahol onemda at gmail.com
Thu Sep 3 10:31:02 EEST 2020


On 9/3/20, rohit khali <khali.rohit at gmail.com> wrote:
> Hi,
>
> I am using
> https://git.ffmpeg.org/gitweb/ffmpeg.git/blob_plain/HEAD:/doc/examples/decode_audio.c
> as
> a base for my audio decoder.
> Audio decoding sounds  ok however looks like ffmpeg outputs decoded PCM
> audio based on codec type. Below are my observations for the sample_fmt.
>
> mpeg1/mpeg2 audio : s16p
> aac,aac_latm,ac3,eac3 : fltp
>
> I want to normalize my decoded PCM output to always " fltp ". I came across
> about AVCodecContext::request_sample_fmt however this setting is not
> working.
> I am trying below code for mpeg1/mpeg2 audio.

You are misinformed, that function works only with codecs that support
multiple sample
formats when decoding, and that is only a few.

You need to use libswresample directly or libavfilter and aformat
filter to change sample audio format.

>    DecCtx = avcodec_alloc_context3(Codec);
>     if (!DecCtx)
>     {
>         return false;
>     }
>
>     DecCtx->request_sample_fmt = AV_SAMPLE_FMT_FLTP;
>
>     if (avcodec_open2(DecCtx, Codec, NULL) < 0)
>     {
>         return false;
>     }
>     const char *sample_fmt = av_get_sample_fmt_name(m_pDecCtx->sample_fmt);
>     printf("[CffmpegAudioDecoder-Open: AVSampleFormat=%s]\n",sample_fmt);
> -->always fetting s16p
>
> I am wondering what am I missing?
> Please help! Thanks in advance.
>
> Regards,
> Rohit Khali
>


More information about the Libav-user mailing list