Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration
@ 2023-08-22 12:03 Ulrik Mikaelsson
  2023-08-23  9:18 ` Tomas Härdin
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrik Mikaelsson @ 2023-08-22 12:03 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: 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.
---
 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,
+                                    (AVRational){1, c.sample_rate},
                                     st->time_base);
     if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
         st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf);
-- 
2.39.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration
  2023-08-22 12:03 [FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration Ulrik Mikaelsson
@ 2023-08-23  9:18 ` Tomas Härdin
  2023-08-23  9:25   ` Ulrik Mikaelsson
  0 siblings, 1 reply; 3+ messages in thread
From: Tomas Härdin @ 2023-08-23  9:18 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

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
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration
  2023-08-23  9:18 ` Tomas Härdin
@ 2023-08-23  9:25   ` Ulrik Mikaelsson
  0 siblings, 0 replies; 3+ messages in thread
From: Ulrik Mikaelsson @ 2023-08-23  9:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

> > ---
> >  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.

Good catch! I also noticed a fate-test failed (due to it including
padding-samples in the reference output for duration), and a
formatting error in the patch itself. Will fix and resubmit.


Den ons 23 aug. 2023 kl 11:18 skrev Tomas Härdin <git@haerdin.se>:
>
> 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
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-23  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 12:03 [FFmpeg-devel] [PATCH] avformat/mp3dec:Subtract known padding from duration Ulrik Mikaelsson
2023-08-23  9:18 ` Tomas Härdin
2023-08-23  9:25   ` Ulrik Mikaelsson

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git