[FFmpeg-devel] [PATCH] avformat/mp3dec: prefer "fast_seek" to TOC seek for CBR files.

Chris Cunningham chcunningham at chromium.org
Tue Nov 17 02:28:58 CET 2015


To test this new patch, again use testcount.mp3
<http://happyworm.com/jPlayerLab/halite/jumptest/testcount.mp3> (CBR,
corrupt TOC).

Current ffmpeg (with none of my mp3 patches)

./ffplay testcount.mp3 -ss 00:33:20 -usetoc 0

plays out "1395", which is correct


./ffplay testcount.mp3 -ss 00:33:20 -usetoc 1
plays out "..378, 1389", which is incorrect due to the corrupted TOC.

./ffplay testcount.mp3 -ss 00:33:20 -fflags fastseek
also plays out "..378, 1389" because current fast_seek logic uses the TOC
whenever available for CBR and VBR alike.


After applying my *latest* patch:

./ffplay testcount.mp3 -ss 00:33:20 -usetoc 0
is unchanged: plays out "1395", which is correct

./ffplay testcount.mp3 -ss 00:33:20 -usetoc 1
is unchanged: still plays out "378, 1389". This is wrong, but it allows
users to force using TOC should they prefer.

./ffplay testcount.mp3 -ss 00:33:20 -fflags fastseek
*is changed: *plays out "1395", which is correct. fast seek no longer uses
the TOC for CBR files.



What do you think? I personally prefer this way so that usetoc is still
meaningful for CBR files.

Thanks,
Chris

On Mon, Nov 16, 2015 at 4:58 PM, <chcunningham at chromium.org> wrote:

> From: Chris Cunningham <chcunningham at chromium.org>
>
> "Fast seek" uses linear interpolation to find the position of the
> requested seek time. For CBR this is more direct than using the
> mp3 TOC and bypassing the TOC avoids problems when the TOC is
> corrupted (e.g. https://crbug.com/545914).
>
> For VBR, fast seek is not precise, so continue to prefer the TOC
> when available.
> ---
>  libavformat/mp3dec.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
> index 32ca00c..e12266c 100644
> --- a/libavformat/mp3dec.c
> +++ b/libavformat/mp3dec.c
> @@ -515,8 +515,10 @@ static int mp3_seek(AVFormatContext *s, int
> stream_index, int64_t timestamp,
>              filesize = size - s->internal->data_offset;
>      }
>
> -    if (   (mp3->is_cbr || fast_seek)
> -        && (mp3->usetoc == 0 || !mp3->xing_toc)
> +    // When fast seeking, prefer to use the TOC when available for VBR
> files
> +    // since av_rescale may not be accurate for VBR. For CBR, rescaling is
> +    // always accurate and more direct than a TOC lookup.
> +    if (fast_seek && (mp3->is_cbr || !mp3->xing_toc)
>          && st->duration > 0
>          && filesize > 0) {
>          ie = &ie1;
> --
> 2.6.0.rc2.230.g3dd15c0
>
>


More information about the ffmpeg-devel mailing list