[FFmpeg-devel] [PATCH] First shot at AVCHD seeking via new seeking API

Ivan Schreter schreter
Sun Aug 16 11:47:02 CEST 2009

Hi Michael,

Michael Niedermayer wrote:
> On Sat, Aug 15, 2009 at 03:03:26PM +0200, Ivan Schreter wrote:
>> Michael Niedermayer wrote:
>>> [...]
>>> ill copy & paste from the nut spec on how to compare timestamps exactly
>>> for more elaborate explanation see the spec yourself
>>>     if (convert_ts(a, a_timebase, b_timebase) < b) return -1;
>>>     if (convert_ts(b, b_timebase, a_timebase) < a) return  1;
>>>     return 0;
>>> (convert_ts here must round down and be exact, the nut spec also
>>>  explains how to do this in C but we already have a fitting function for
>>>  it)
>> Yes, I can do it this way.
>> BUT: This makes the code more complex and marginally slower, as I have to 
>> keep track of which time base was used for which timestamp, as not only 
>> comparisons of timestamps are done, but also computation of minimal 
>> distance with timestamps involving various streams. Especially for the 
>> computation of minimal distance, I have to create a synthetic time base as 
>> the product of two time bases used for two timestamps to subtract, to 
>> exactly represent the distance without loss of precision.
>> Is that OK for you?
> no, our code does not work for combined (64/64) time bases
> and i dont see why or where such timebases would become needed
I solved the comparison a little differently (see function compare_ts), 
so it now takes time bases into account. Basically we compare two 
rational numbers Ta*Na/Da and Tb*Nb/Db, so we can as well compare 
Ta*Na*Db and Tb*Nb*Da, which is exact (both rational numbers multiplied 
by Da*Db). Unfortunately, border cases with INT64_MIN/MAX have to be 
taken into account.

As for the timestamp difference, only differences of two timestamps with 
same two timebases are compared to find closer timestamp. Basically, for 
each stream, I have to compute differences of timestamps inside this 
stream with user-specified timestamp, which has possibly different time 
base. So I wrote a function (ts_distance) to compute exact difference of 
timestamps in some opaque units. Similarly to the above, we have two 
rational numbers Ta*Na/Da and Tb*Nb/Db. The distance can be computed as 
Ta*Na*Db - Tb*Nb*Da, which is basically distance as rational number 
multiplied by (Da*Db). This distance can be safely compared with another 
distance between Ta'*Na/Da and Tb'*Nb/Db, as long as time bases Na/Da 
and Nb/Db are the same.

I think it's clean and 100% exact now.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_cooked_lavf.patch
Type: text/x-patch
Size: 25892 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090816/d7cf81d9/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_cooked_mpegts.patch
Type: text/x-patch
Size: 4273 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090816/d7cf81d9/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seek_cooked_seekregress.patch
Type: text/x-patch
Size: 4428 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090816/d7cf81d9/attachment-0002.bin>

More information about the ffmpeg-devel mailing list