[vlc-devel] Re: DEMUX_GET/SET_TIME for TS

Derk-Jan Hartman hartman at videolan.org
Thu Mar 9 15:16:27 CET 2006

On 9-mrt-2006, at 14:12, TW wrote:
> Hi all,
> Any ideas out there on how to approach the DEMUX_GET_TIME and
> DEMUX_SET_TIME operations for transport streams?

Current situation:
Only file-position, file-length and muxing-rate are known. You can  
make a guess based on the muxing-rate, but it will be very  
unreliably, since it is often set incorrect, or in the case of VBR  
usually denotes the highest or the average bit-rate of the file.

What is needed first is DEMUX_GET_LENGTH
Basically there are two ways to do this:
1: Get first PTS of a PES in the file, seek to end, find the same PES  
stream and find the last packet of that stream and find the PTS of  
that. Substract values, make sure they are > 0 and assume this as the  
length of the file. For increased reliability, take the PTS'es of all  
PES streams, and make a reliable guess based on all streams.
However because TS can start and stop at any time, contain gaps or  
loops, a stream can contain multiple programs etc etc, This method  
will be unreliable.

2: Completely parse the ENTIRE file, detecting all the above events,  
and based on this reconstruct a proper length of the file. (ProjectX  
does this)

For DEMUX_GET/SET_TIME, you can simply take the LENGTH of the movie  
and based on the position in the file calculate a TIME. However this  
will be unreliable in that if the file is VBR, more complex parts of  
the movie (with a higher bit-rate), will occupy more space in the  
file, thus causing desynchronisation between REAL time and calculated  
time. You then will witness for instance that in the VLC reported  
time a second in the file might be 2 seconds or 1/2 a second on the  
VLC  timeline.

The other approach is to take the PTS of the same PES stream and use  
that minus PTS starttime as the current time. This is again sensitive  
to gaps etc in the timeline.

The 3rd approach for GET/SET_TIME requires #2 of GET_LENGTH and  
creating a timeindex (much as for avi/mp4/matroska etc) to get the  
times for file-offsets.


BTW, similar issues go for almost all the Raw audio formats, OGG, as  
well as PS, VOB, etc.

This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://developers.videolan.org/lists.html

More information about the vlc-devel mailing list