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

chcunningham at chromium.org chcunningham at chromium.org
Tue Nov 17 01:58:57 CET 2015


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