[FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration

Tomas Härdin git at haerdin.se
Wed Aug 23 12:18:12 EEST 2023


tis 2023-08-22 klockan 14:03 +0200 skrev Ulrik Mikaelsson:
> When an Info-tag is present, marking initial and trailing samples as
> padding, those samples should not be included in the calculation of
> track
> duration.
> 
> This solves a surprising user experience where converting a WAV->MP3-
> >WAV,
> ffprobe will show the duration of the mp3 as slightly longer than
> both the
> input and the output.

I've had similar issues with burning gapless CDs. Hopefully this fixes
some downstream projects.

> ---
>  libavformat/mp3dec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
> index 05c13228bc..c8c3b298ab 100644
> --- a/libavformat/mp3dec.c
> +++ b/libavformat/mp3dec.c
> @@ -350,7 +350,8 @@ static int mp3_parse_vbr_tags(AVFormatContext *s,
> AVStream *st, int64_t base)
>      avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
>  
>      if (mp3->frames)
> -        st->duration = av_rescale_q(mp3->frames, (AVRational){spf,
> c.sample_rate},
> +        st->duration = av_rescale_q((mp3->frames * spf) - mp3-
> >start_pad - mp3->end_pad,

This can overflow. Casting to int64_t before multiplying should be
enough to fix it.

/Tomas


More information about the ffmpeg-devel mailing list