[FFmpeg-devel] [PATCH] Fix MPEG-TS seek and frame positions in general

Ivan Schreter schreter
Sat Feb 7 01:50:44 CET 2009


Hi,

I am working on getting files from my AVCHD camcorder fully supported by 
ffmpeg. I noticed that MPEG-TS seeking is broken. Unfortunately, it has 
not been trivial to fix. Here is a set of 7 patches, which address the 
issue.

Patch #1: trivial patch to move av_read_frame_flush() to internal.h 
(needed later).

Patch #2: let mpegts format decoder return correct packet positions by 
keeping track of position of first TS packet of a PES packet in 
MpegTSPESFilter.

Patch #3: trivial patch to handle decoding delays >1 correctly. Some 
decoders (namely h264) set has_b_frames to >1 after seek, but only for 
explicitly 1 is checked here. Can be applied independently of the rest 
of the patches.

Patch #4: make av_read_frame fill packet position correctly by keeping 
track of the position of first packet of a frame in AVStream.cur_pos.

Patch #5: mpegts seek only searches for a PES packet with correct pid 
and existing DTS and relies on this being a key frame. This is not even 
the case in the test file. Read frames via av_read_frame until a key 
frame is found and return position/timestamp of this frame. This needs 
#1 to reset the packet reader after reading the frames, so further reads 
work correctly, #2 to have correct positions from mpegts and #4 to have 
exact position of the packet for later file seek.

Patch #6: optimization of seeking by keeping track of min/max position 
and timestamp on AVStream instead of computing them over and over again. 
Can be applied independently of the rest of the patches.

Patch #7: since patches #4 and #5 change packet positions and correct 
mpegts seeking, seek regression has to be adjusted appropriately. 
Contains the delta for seek regression file.

Please review/apply the patches.

Thanks & regards,

Ivan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_1_avformat_flush.patch
Type: text/x-patch
Size: 925 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_2_mpegts_pos.patch
Type: text/x-patch
Size: 2840 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_3_delay.patch
Type: text/x-patch
Size: 1224 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_4_frame_pos.patch
Type: text/x-patch
Size: 2728 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_5_mpegts_keyframe.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_6_optim_minmax.patch
Type: text/x-patch
Size: 2807 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_7_regres.patch
Type: text/x-patch
Size: 61802 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090207/b0f2b0ea/attachment-0006.bin>



More information about the ffmpeg-devel mailing list