[Libav-user] Why does av_seek_frame() not seek to a keyframe?

Michael Bradshaw mbradshaw at sorensonmedia.com
Thu Jul 19 19:13:31 CEST 2012


On Thu, Jul 19, 2012 at 12:18 AM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> Michael Bradshaw <mbradshaw at ...> writes:
>
>> But when I seek, the first packet returned out of the demuxer is
>> not a keyframe packet, and I have to read several (~45ish) packets
>> until I encounter a keyframe.
>
> Could you provide a sample that does not seek to a keyframe with
> ffmpeg -ss x -i input out.png
> (I tested this yesterday on random mpeg2video samples and afaict,
> it did work.)

Sure, here's a link to a sample video I'm testing with (sorry, it's
785 MB): https://doc-04-50-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/t0csnri6mmjsd3mqbnb8qdv7b1tiq1e8/1342713600000/11977383638970716307/*/0BxWx_dIBnyRoZDNDeDVud3NNcEE?e=download

I modified ffmpeg.c to print out where it sought to and the packet
flags whenever av_read_frame() is done (those are the only changes I
made). Here's the complete output. Notice that "packet.flags:0 [...]
Last message repeated 53 times" before a keyframe is found. This is
the latest ffmpeg (updated and built last night), testing on Windows
with MinGW shell:

$ ./ffmpeg.exe -ss 38 -i 704x480-m2v-ac3.mpg -vframes 1 out.jpg
ffmpeg version 0.11.1.git Copyright (c) 2000-2012 the FFmpeg developers
  built on Jul 18 2012 18:11:46 with gcc 4.6.2
  configuration:
  libavutil      51. 65.100 / 51. 65.100
  libavcodec     54. 41.100 / 54. 41.100
  libavformat    54. 17.100 / 54. 17.100
  libavdevice    54.  1.100 / 54.  1.100
  libavfilter     3.  2.100 /  3.  2.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
[mpegts @ 0162c3c0] max_analyze_duration 5000000 reached at 5005000
[mpegts @ 0162c3c0] PES packet size mismatch
    Last message repeated 6 times
sought to position 87711.750
Input #0, mpegts, from '704x480-m2v-ac3.mpg':
  Duration: 00:42:06.54, start: 87673.749689, bitrate: 2607 kb/s
  Program 1
    Stream #0:0[0x41]: Video: mpeg2video (Main) ([2][0][0][0] /
0x0002), yuv420p, 704x480 [SAR 40:33 DAR 16:9], 15000 kb/s, 29.97 fps,
29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x44](eng): Audio: ac3 ([129][0][0][0] / 0x0081),
48000 Hz, stereo, s16, 192 kb/s
    Stream #0:2[0x45](spa): Audio: ac3 ([129][0][0][0] / 0x0081),
48000 Hz, stereo, s16, 192 kb/s
Output #0, image2, to 'out.jpg':
  Metadata:
    encoder         : Lavf54.17.100
    Stream #0:0: Video: mjpeg, yuvj420p, 704x480 [SAR 40:33 DAR 16:9],
q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> mjpeg)
Press [q] to stop, [?] for help
packet.flags:0
    Last message repeated 53 times
packet.flags:1
packet.flags:0
    Last message repeated 2 times
frame=    1 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.03 bitrate=
0.0kbits/s dup=0 drop=1
video:32kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000000%

Thanks,

Michael


More information about the Libav-user mailing list