Log in

View Full Version : Updating MPEG-2 timestamps when chopping


lc204
28th September 2007, 23:37
I'm trying to understand what needs to be updated in the mpeg when extracting several pieces within an mpeg and then joining them together. Besides the SCR in the pack header and the PTS, DTS...is there anything else I'm missing? Does the GOP timestamp need to be updated as well? Thanks.

Guest
29th September 2007, 04:43
It depends on your purpose. E.g., in the broadcast world usually nothing is done -- there is just a big discontinuity when a new stream begins. The AV sync process is smart enough to ignore it and resync on the new stream of timestamps. After all, the PTS is a limited size so it eventually wraps. Thus decoders have to be able to handle sudden discontinuities without going haywire.

What is your purpose?

lc204
29th September 2007, 06:05
I want to chop up an mpeg, join it programatically, and then transcode the result to wmv using 3rd party software. I've adjusted the SCR, PTS, and DTS for the packs that I've parsed out and the mpeg plays fine in windows media player using intervideo's codec. However when I transcode it to wmv using a 3rd party software, I lose the audio and the duration is off. It could be the decoder used for transcoding is more strict. It'll transcode the non-edited mpeg fine with no problem so I'm guessing I must be missing something. I'm still learning the structure of mpeg2 so excuse me if my understanding is wrong.

Guest
29th September 2007, 14:55
As a workaround to get the stamps corrected, try this approach. Demux the audio and video streams from your edited MPEG and then remux them.

It's hard to know what your encoder is barfing at so maybe it's better to finesse the problem this way.

lc204
29th September 2007, 19:32
Thanks for the help. Is there a tool that logs the errors in the stream when demuxing or remuxing while it's correcting? I want to pinpoint the problem rather than relying on a workaround.

The logic I'm using to parse the packs I want is to look at the SCR for each pack and if it falls within a range, I copy it out and adjust the timestamps. I've also included the first pack from the original which includes the system header and stream map. I'm doing this without demuxing which I think is the reason why I'm having problems.

ronnylov
29th September 2007, 23:24
You could try projectX which logs and corrects errors while demuxing.

http://project-x.sourceforge.net/

lc204
1st October 2007, 04:36
Thanks! I'll definately give it a try.

Schmendrick
1st October 2007, 17:20
A good way is to split your original source stream and correct any minor faults at the same time using project-x as ronnylov has suggested you can also demux it at the same time. With MPEGSchnitt ( http://www.doom9.org/Soft21/DigiTV/Mpeg2Schnitt087.zip ) you can join the different clips and remux them together.

In the case of ts-files you can use tsremux to recalculate the PTS-values (and DTS values??) of a ts-file merged from different ts-clips.

Schmendrick

lc204
1st October 2007, 21:43
Thanks. I was hoping I could split and join without demuxing. Also, all the tools I've seen don't provide command line options for automatting either demux/remux or split/join given a list of mark points.