seeking in mpegtsdemux
Janne Grunau
janne.grunau at collabora.co.uk
Tue Feb 22 06:17:29 PST 2011
Hi,
I'm currently writing seeking support for the MPEG TS demuxer rewrite.
Since MPEG TS as streaming format lacks any index the seeking
implementation has to build it's own index.
The basic algorithm I intend to use is an hinted binary search. For
constant bitrate streams estimating the position and a linear search
from the estimated position should work well. Variable bitrate streams
can vary too much (factor 3 is not unusual for HD H.264 broadcast).
So the idea is to do a binary search but instead of choosing the
midpoint for the next iteration a educated guess based on the average
bitrate of the segment is taken. The average bitrate will converge to
the actual bitrate as the segments get smaller. Of course only up to a
certain point, 2 B-frames will be smaller than an I-frame but at this
point a linear search should be used.
For large files this algorithm should need less seeks than a simple
binary at the file system level. I've already started and hope to have
something working at the end of the week.
There are currently two issues I would like to get some feedback on.
*handling of multiple program/streams:
I can't think of a valid example where multiple programs in a single
multiplex have different durations (assuming they both stay "on-air").
Unless someone can think of valid use case, the scaffold will be per
file and not per program/stream.
*frame accurate seeking:
seeking to the frame with the desired PTS is unfortunately only part
of the solution. If the application wants to seek to a correctly decoded
(bi-)predicted frame the demuxer needs to return all reference frames
too. This is not too hard for MPEG2 video but MPEG2 is becoming
obsolete. H264 is unfortunately much more complex (not speaking about
other video codecs). The random access indicator in the adaption field
is unfortunately not reliable. I haven't seen it set.
I'll probably have more questions as I implement it.
Janne
More information about the gstreamer-devel
mailing list