[FFmpeg-devel] [PATCH] avcodec/utils: Add case for mp3 to av_get_audio_frame_duration()

Ronald S. Bultje rsbultje at gmail.com
Fri Jan 1 19:29:34 CET 2016


Hi,

On Fri, Jan 1, 2016 at 11:43 AM, Michael Niedermayer <michaelni at gmx.at>
wrote:

> From: Michael Niedermayer <michael at niedermayer.cc>
>
> This is not guranteed to be correct but only the encoder or the packet
> headers
> can really provide the correct value. And before the first packet there is
> no alternative to receiving the value from the encoder by some means
>
> other codecs like AAC are still missing and are left for voluteers
>
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavcodec/utils.c |    6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 4b4aea0..6ed47ef 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -3042,6 +3042,12 @@ int av_get_audio_frame_duration(AVCodecContext
> *avctx, int frame_bytes)
>          if (id == AV_CODEC_ID_TTA)
>              return 256 * sr / 245;
>
> +        // When frame_bytes is set then the headers can be parsed to find
> the
> +        // frame size
> +        if (id == AV_CODEC_ID_MP3 && !frame_bytes) {
> +            return sr <= 24000 ? 576 : 1152;
> +        }
> +
>          if (ch > 0) {
>              /* calc from sample rate and channels */
>              if (id == AV_CODEC_ID_BINKAUDIO_DCT)
> --
> 1.7.9.5


Please, no more codec-specific hacks in generic code.

Ronald


More information about the ffmpeg-devel mailing list