[FFmpeg-trac] #1607(avformat:new): av_seek_frame() without AVSEEK_FLAG_ANY on mpg files returns success without seeking to a keyframe
FFmpeg
trac at avcodec.org
Tue Aug 7 20:17:58 CEST 2012
#1607: av_seek_frame() without AVSEEK_FLAG_ANY on mpg files returns success
without seeking to a keyframe
------------------------------------+------------------------------------
Reporter: mbradshaw | Owner:
Type: defect | Status: new
Priority: normal | Component: avformat
Version: git-master | Resolution:
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
------------------------------------+------------------------------------
Comment (by mbradshaw):
Replying to [comment:10 cehoyos]:
> Replying to [comment:5 mbradshaw]:
> > The problem isn't that you get a junk frame out (the decoder makes
sure you don't).
>
> I wonder what this sentence means: There are many samples that return
gray frames for above command line (including some sample that you pointed
to).
Really? I don't get any gray frames with those commands. I get good
looking frames out, but that's because the decoder swallows the non-
keyframes after the seek and ffmpeg keeps reading until it gets a keyframe
packet and the decoder finally returns a full frame. I get:
{{{
./ffmpeg -ss 1 -i ~/mpeg2video_seek_to_non_keyframe.mpg ~/out.png
ffmpeg version N-43294-g8993c25 Copyright (c) 2000-2012 the FFmpeg
developers
built on Aug 7 2012 12:02:23 with gcc 4.2.1 (GCC) (Apple Inc. build
5666) (dot 3)
configuration:
libavutil 51. 66.101 / 51. 66.101
libavcodec 54. 50.100 / 54. 50.100
libavformat 54. 22.101 / 54. 22.101
libavdevice 54. 2.100 / 54. 2.100
libavfilter 3. 5.102 / 3. 5.102
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
[mpeg @ 0x10180ec00] max_analyze_duration 5000000 reached at 5024000
Input #0, mpeg, from '/Users/mjbshaw/mpeg2video_seek_to_non_keyframe.mpg':
Duration: 00:00:09.85, start: 1.320000, bitrate: 4998 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR
16:15 DAR 4:3], 8000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s
Output #0, image2, to '/Users/mjbshaw/out.png':
Metadata:
encoder : Lavf54.22.101
Stream #0:0: Video: png, rgb24, 720x576 [SAR 16:15 DAR 4:3], q=2-31,
200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video -> png)
Press [q] to stop, [?] for help
[mpeg2video @ 0x10180f200] warning: first frame is no keyframe
[image2 @ 0x10180f800] Could not get frame filename number 2 from pattern
'/Users/mjbshaw/out.png'
av_interleaved_write_frame(): Invalid argument
}}}
The output image looks okay though. The key here is the same thing Don
points out (the `[mpeg2video @ 0x10180f200] warning: first frame is no
keyframe` part). If you're able to get gray frames out with that command
then something's different between our ffmpegs...
@Don: I don't think (someone please correct me if I'm wrong) that
specialized code can really be written for the mpeg's AVInputFormat seek
function because of the structure of mpeg's. I think it would just be
better to fix `ff_seek_frame_binary()`, because if custom code was written
for mpeg's it would end up being so similar to `ff_seek_frame_binary()`.
IIUC, mpeg's are impossible to properly seek by keyframes reliably, and
the best solution would be to do a binary search for a frame, and then
after finding it, sequentially reading (either forwards or backwards) to
the next keyframe.
--
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/1607#comment:12>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list