MPEG, GOP, TiVo's own mplex'd format, help!

Warren Toomey wkt at t...
Thu, 17 Jan 2002 22:00:25 +1000 (EST)


Hi all,
I was thinking of altering my Playitsam tool to cut the video
stream at Group of Picture (GOP) points, so as to produce an edited
tystream which is still essentially an intact MPEG-2 stream.

I can find the GOP markers in the TiVo tystreams, and with some
work I could write the code to trim out whole groups of GOPs.

Now, how am I going to trim out the right amount of audio stream to
keep them both in sync?

In the tystream format, it seems that there are audio and video
sections which are 16 bytes in length. These seem to be timing
marks. Does anybody know how to decode them?

Here's an example, the second chunk from a tystream. ofs == offset
in decimal. I print the start of the record's data in hex on the right:

Chunk 1 has 26 records
* #00 size 00016 ofs 00420 aud: 00 00 01 c0 10 ea 8c 80 07 21 00 07 04 7b ff ff 
#01 size 00864 ofs 00436 aud: ff fd a8 00 44 22 22 43 33 22 22 33 33 33 22 49 
#02 size 00864 ofs 01300 aud: ff fd a8 00 33 22 11 11 22 22 11 21 33 33 44 72 
#03 size 00864 ofs 02164 aud: ff fd a8 00 44 33 22 33 33 44 33 33 33 33 33 6d 
#04 size 00864 ofs 03028 aud: ff fd a8 00 33 33 33 55 55 44 22 22 11 33 22 26 
#05 size 00864 ofs 03892 aud: ff fd a8 00 33 22 11 22 22 12 11 22 33 22 44 92 
* #06 size 00016 ofs 04756 vid: 00 00 01 e0 00 00 8c 80 07 21 00 07 4e 89 ff ff 
#07 size 00084 ofs 04772 vid: 00 00 01 b3 22 02 40 23 08 8b a3 81 10 11 11 12 
#08 size 00004 ofs 04856 vid: 00 00 00 00 
#09 size 00004 ofs 04860 vid: 00 00 00 00 
#10 size 00004 ofs 04864 vid: 01 b8 00 08 
#11 size 00004 ofs 04868 vid: 00 40 00 00 
#12 size 00004 ofs 04872 vid: 00 00 00 00 
#13 size 51632 ofs 04876 vid: 01 00 00 8c 07 90 00 00 01 b5 8f ff f3 9c 00 00 
#14 size 00004 ofs 56508 vid: 6b 00 00 00 
#15 size 00004 ofs 56512 vid: 00 00 00 00 
#16 size 04044 ofs 56516 vid: 01 00 00 1b 2c 23 b8 00 00 01 b5 83 23 23 9c 00 
#17 size 00004 ofs 60560 vid: 2c 14 80 00 
#18 size 00004 ofs 60564 vid: 00 00 00 00 
#19 size 05688 ofs 60568 vid: 00 01 00 00 5b 82 9b b8 00 00 01 b5 83 23 23 9c 
#20 size 30708 ofs 66256 vid: 00 00 01 00 01 53 ce 83 80 00 00 01 b5 85 2f f3 
#21 size 07068 ofs 96964 vid: 00 00 01 00 00 db 79 9b b8 00 00 01 b5 83 23 23 
#22 size 08324 ofs 104032 vid: 00 00 01 00 01 1b bc ab b8 00 00 01 b5 83 23 23
#23 size 00004 ofs 112356 vid: 2e 20 c0 00 
#24 size 00004 ofs 112360 vid: 00 00 00 00 
#25 size 18580 ofs 112364 vid: 00 01 00 02 13 f7 a3 80 00 00 01 b5 83 4f f3 9c
Found GOP at 4862
total video: 0x1ecec total audio: 0x10f0 total: 0x1ff80
total video: 126188 total audio: 4336 total: 130944 diff 128

I've starred the two 16-byte `timing' records. Note that the video GOP marker
is at offset 4862 in this chunk.

Question: Say the GOP marker was at offset 96964, and I wanted to
trim out the video from this point on. How would I work out how to
trim the right amount of audio too?

Thanks in advance for any and all ideas!

Warren