[mythtv] Changeset 12847 - Add TS support to mythtranscode

Paul Harrison mythtv at dsl.pipex.com
Sat Feb 24 10:58:15 UTC 2007

Geoffrey Hausheer wrote:
> On 2/22/07, Paul Harrison wrote:
>> One change I did make to mythreplex was to work around a problem when
>> mythtranscode is used to remove commercials from an mpeg2 file and  then
>> mythreplex is the used to split the file. After each cut the audio gets
>> further and further out of sync. My understanding from an explanation
>> from Daniel is that the length (in time) of the audio and video packets
>> don't always match up at the cut points. mythtranscode must allow for
>> this by changing the time codes around cut points because the resulting
>> file plays fine but when the file is split these differences add up and
>> after 5 or more cuts there is quite a noticeable sync difference. Is
>> there any way mythtrancode could keep track of these differences and
>> compensate for them so the hack in mythreplex to compensate could be
>> removed?
> It's not really possible to do this properly (which is why I didn't)
> because the framerates are different between audio and video.  This is
> one reason why mythtranscode was written in the first place, since all
> other utilities seem to split the stream losing the timecodes in the
> process before doing manipulation.  If you told me what you did to
> hack around the issue, I my be able to do something similar, but if
> the input stream is broken (and I've seen lots of those) I believe it
> will be very hard to do properly (basically requires re-encoding the
> audio).
> It would be better if I understood why you needed to split the streams
> in the 1st place, as this is generally a poor way to deal with MPG,
> which is specifically designed to use the PES packets for
> synchronization.
> .Geoff
I need to split the files as part of the DVD creation process used by 
MythArchive. There's several reasons it's done . One is so I can use 
mplex to remux the video and audio streams back together adding the NAV 
packets needed to create the DVD. Second in order to create compliant 
DVD's in ntsc countries the mp2 audio stream needs to be converted to 
ac3. It also allows us to pick and choose which audio stream(s) to use 
in the DVD if there are several available to pick from.

The hack used in mythreplex detects jumps in the pts and either inserts 
or deletes audio frames to compensate. If an audio frame needs to be 
added then a blank (silent) frame is encoded and inserted. If a frame 
needs to be removed then the frame is just skipped over when writing the 

If you want to reproduce the problem yourself here are the steps which 
reproduces the it every time for me.

The '/media/store' directory is where myth stores my recordings and 
'/media/mythburn/work' is a temp directory to hold the temporary work files.

1. use myth to edit a recording and add lots of cut points.

2.  run mythtranscode  --mpeg2 to cut the file
$ mythtranscode --mpeg2 --honorcutlist -i 
/media/store/2003_20070222223000.mpg -o /media/mythburn/work/test.mpg

3. run mythreplex to split the file
$ mythreplex --demux -o /media/mythburn/work/stream -v 224 -a 224 

4. use mplex to remux the streams back together adding the NAV packets
$ mplex -f 8 -o /media/mythburn/work/final.mpg 
/media/mythburn/work/stream.mv2 /media/mythburn/work/stream0.mp2

If you now  play the final.mpg file you should see the audio starts in 
sync but after each cut it gets further out of sync.

If you now repeat the process from step 3 and add '--fix_sync' to the 
mythreplex command which enables the hack you should see a file where 
everything stays in sync at least that is what I see. One user said it 
makes things worse not better for files that have been run though 
mythtranscode --mpeg2 twice though.

The original trac ticket where the problem was reported is here :-

Paul H.

More information about the mythtv-dev mailing list