Opened 14 years ago

Closed 13 years ago

#271 closed defect (fixed)

regression with seeking in avi

Reported by: ami_stuff Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

http://www.datafilehost.com/download-39b73242.html

seeking with ffplay in attached file doesn't work correctly, seems like a regression because of this patch:

avidec: correct frame_offset for seeking
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=187528441ab936c102b8e72f38925cc10fc14abc
---

 libavformat/avidec.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 98b3be6..7e97b7b 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1303,7 +1303,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
 {
     AVIContext *avi = s->priv_data;
     AVStream *st;
-    int i, index;
+    int i, index, j;
     int64_t pos, pos_min;
     AVIStream *ast;
 
@@ -1367,6 +1367,22 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
             index=0;
         ast2->seek_pos= st2->index_entries[index].pos;
         pos_min= FFMIN(pos_min,ast2->seek_pos);
+    }
+    for(i = 0; i < s->nb_streams; i++) {
+        AVStream *st2 = s->streams[i];
+        AVIStream *ast2 = st2->priv_data;
+
+        if (ast2->sub_ctx || st2->nb_index_entries <= 0)
+            continue;
+
+        index = av_index_search_timestamp(
+                st2,
+                av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
+                flags | AVSEEK_FLAG_BACKWARD);
+        if(index<0)
+            index=0;
+        while(index>0 && st2->index_entries[index-1].pos >= pos_min)
+            index--;
         ast2->frame_offset = st2->index_entries[index].timestamp;
     }
C:\>ffmpeg -i reszort.avi
ffmpeg version git-N-30558-ge844abc, Copyright (c) 2000-2011 the FFmpeg develope
rs
  built on Jun  5 2011 08:19:16 with gcc 4.5.3
  configuration: --enable-gpl --enable-version3 --enable-memalign-hack --enable-
runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libo
pencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --
enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger
 --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enabl
e-libx264 --enable-libxavs --enable-libxvid --enable-zlib --disable-outdev=sdl -
-pkg-config=pkg-config
  libavutil    51.  4. 0 / 51.  4. 0
  libavcodec   53.  6. 1 / 53.  6. 1
  libavformat  53.  2. 0 / 53.  2. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 12. 0 /  2. 12. 0
  libswscale    0. 14. 1 /  0. 14. 1
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, avi, from 'reszort.avi':
  Metadata:
    creation_time   : 2003-09-04 21:58:30
  Duration: 00:00:38.03, start: 0.000000, bitrate: 824 kb/s
    Stream #0.0: Video: msmpeg4v1, yuv420p, 192x144, 14.98 fps, 14.98 tbr, 14.98
 tbn, 14.98 tbc
    Stream #0.1: Audio: pcm_s16le, 22050 Hz, 1 channels, s16, 352 kb/s
At least one output file must be specified
C:\>ffmpeg -i reszort.avi
ffmpeg version git-N-30558-ge844abc, Copyright (c) 2000-2011 the FFmpeg develope
rs
  built on Jun  5 2011 08:19:16 with gcc 4.5.3
  configuration: --enable-gpl --enable-version3 --enable-memalign-hack --enable-
runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libo
pencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --
enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger
 --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enabl
e-libx264 --enable-libxavs --enable-libxvid --enable-zlib --disable-outdev=sdl -
-pkg-config=pkg-config
  libavutil    51.  4. 0 / 51.  4. 0
  libavcodec   53.  6. 1 / 53.  6. 1
  libavformat  53.  2. 0 / 53.  2. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 12. 0 /  2. 12. 0
  libswscale    0. 14. 1 /  0. 14. 1
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, avi, from 'reszort.avi':
  Metadata:
    creation_time   : 2003-09-04 21:58:30
  Duration: 00:00:38.03, start: 0.000000, bitrate: 824 kb/s
    Stream #0.0: Video: msmpeg4v1, yuv420p, 192x144, 14.98 fps, 14.98 tbr, 14.98
 tbn, 14.98 tbc
    Stream #0.1: Audio: pcm_s16le, 22050 Hz, 1 channels, s16, 352 kb/s
At least one output file must be specified

Change History (5)

comment:1 by Michael Niedermayer, 14 years ago

Resolution: fixed
Status: newclosed

will be fixed with my next push

comment:2 by exobuzz, 14 years ago

I see this bug is marked as fixed on git. I just rebuilt ffmpeg from source from this version

commit 54dd50d14dc3a3952f7d85165142d02f6ea578d7 Date: Mon Jun 20 13:22:23 2011 +0200

perhaps my problem is not the same, but the same referenced patch "avidec: correct frame_offset for seeking" breaks seeking on a mpeg4 file. when seeking there are block artifacts (which disappear at the next key frame). the file is 5713978482 bytes in length. if i chop (with dd) the first 20 or 200mb of the file, the piece seeks correctly. (testing with ffplay)

playing (and seeking) the full file with the problem

$ ./ffplay artifacts_when_seeking.avi 
ffplay version N-30884-g54dd50d, Copyright (c) 2003-2011 the FFmpeg developers
  built on Jun 20 2011 23:10:06 with gcc 4.5.2
  configuration: 
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    0. 14. 1 /  0. 14. 1
[avi @ 0x13b01c0] non-interleaved AVI
Input #0, avi, from 'artifacts_when_seeking.avi':
  Metadata:
    encoder         : MEncoder 1.0rc4-4.5.2
  Duration: 02:13:54.16, start: 0.000000, bitrate: 5689 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 1280x544 [PAR 1:1 DAR 40:17], 24 tbr, 24 tbn, 24 tbc
    Stream #0.1: Audio: dca (DTS), 48000 Hz, 5.1, s16, 1536 kb/s
[dca @ 0x13af5e0] Not a valid DCA frame=   43KB sq=    0B f=0/0   f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=   27KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe
[dca @ 0x13af5e0] Not a valid DCA frame=  285KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  575KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  682KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  627KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  674KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  378KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
[dca @ 0x13af5e0] Not a valid DCA frame=  423KB sq=    0B f=0/0   
[mpeg4 @ 0x13675c0] warning: first frame is no keyframe0B f=0/0   
 188.34 A-V:  0.008 s:0.0 aq=  321KB vq=  392KB sq=    0B f=0/0  

revert two related commits

$ git revert -n a7e4342fc1a0e962b829a9a194d034fa38590951
$ git revert -n 187528441ab936c102b8e72f38925cc10fc14abc

i am then able to seek ok without the artifacts

$ ./ffplay artifacts_when_seeking.avi 
ffplay version N-30884-g54dd50d, Copyright (c) 2003-2011 the FFmpeg developers
  built on Jun 20 2011 23:10:06 with gcc 4.5.2
  configuration: 
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    0. 14. 1 /  0. 14. 1
[avi @ 0x2d850c0] non-interleaved AVI
Input #0, avi, from 'artifacts_when_seeking.avi':
  Metadata:
    encoder         : MEncoder 1.0rc4-4.5.2
  Duration: 02:13:54.16, start: 0.000000, bitrate: 5689 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 1280x544 [PAR 1:1 DAR 40:17], 24 tbr, 24 tbn, 24 tbc
    Stream #0.1: Audio: dca (DTS), 48000 Hz, 5.1, s16, 1536 kb/s
[dca @ 0x2d844c0] Not a valid DCA frame=   19KB sq=    0B f=0/0   f=0/0   
 364.79 A-V: -0.002 s:0.0 aq=  319KB vq=  840KB sq=    0B f=0/0   
    Last message repeated 8 times

here is a snippet from the beginning of the file (20mb). if you need anything else please let me know.
http://www.datafilehost.com/download-a1793e98.html

comment:3 by exobuzz, 14 years ago

Resolution: fixed
Status: closedreopened

comment:4 by exobuzz, 13 years ago

have moved my issue to separate bug as requested by michael. Issue is now reported on #327. I don't have permission to close this again. Sorry for any inconvenience.

comment:5 by Carl Eugen Hoyos, 13 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.