Log in

View Full Version : How can I cut a Transport Stream?


Ludicrous of Boorg
15th September 2009, 18:34
I have a Hauppage ATSC tuner. I used to use it with Windows, and its software captured video produced a .mpg file. I then cut commercials out with MPG2CUT2, thanks to advice from these forums, and worked with it from there.:thanks:

I've since built a better computer with Linux (Ubuntu 9.04 64-bit). I can capture video with Kaffeine, but that produces an MPEG2 Transport Stream. The best thing I found to cut this is still MPG2CUT2 in Wine, but it warns that it doesn't always do this right. I'm beginning to believe it, since every encoding method I've tried to make a DivX/MPEG4 AVI file from that had one problem or another, most involving the cut points. A couple of encoders may work with the cut video, but have other problems, so I'd like to avoid this approach if I can. I suppose I could cut the resulting AVI, but that could leave 5 seconds of commercials or more in at each break; and watching commercials in videos I make is no way to go through life! ;)

I've tried both ProjectX and RePlex 0.1.6 for converting the video to a packet stream so I can use MPG2CUT2. ProjectX says it doesn't support ATSC, and it doesn't seem to. RePlex I just tried, but it gives me a buffer overflow.

So I'm looking for either an easy way to cut the transport stream around commercials, or a way to convert it to a packet stream. One option is DgIndex + AviSynth, but copy/pasting the frame numbers of the beginnings and ends of commercials, after preprocessing, is not what I call easy; plus encoding that with VirtualDub is way slower than Handbrake. Any suggestions?

nm
15th September 2009, 19:13
How about Avidemux?

Ludicrous of Boorg
15th September 2009, 20:13
I think that's one of the first things I tried (a month or two ago; this is a hard problem!) Avidemux doesn't maintain audio sync; the video starts out ahead of the audio, and when I sync the beginning of the clip, the video slowly gets farther and farther ahead, whether I transcode to another format or just copy. I know DGIndex complains about field order transitions; maybe there are framerate transitions as well?

Ludicrous of Boorg
15th September 2009, 20:48
I forgot to post a clip! So here's one:

http://rapidshare.com/files/280560774/commercialclip.TS.html

The audio sync is fine in (Edit:)VLC. DGIndex says the audio offset should be -333ms; but that doesn't get the lips synced in AviDemux.

nm
15th September 2009, 22:59
dvbcut (http://dvbcut.sourceforge.net/) seems to work on that file and the user interface is very nice for removing commercials. I used SVN r166 from debian-multimedia.org (http://debian-multimedia.org/). I'm not sure if there are newer Ubuntu packages than this: https://launchpad.net/~fabricesp/+archive/ppa

Ludicrous of Boorg
16th September 2009, 00:16
:thanks:

That works great! I compiled 0.5.4 from source, and had to fix a few bugs, in case anyone else wants to try:

- on line 388 of buffer.cpp, I added ", 00644" at the end of the open().
- I added #include <stdlib.h> to both mpegmuxer.cpp and mpgfile.cpp
- I changed line 41 of playaudio.cpp to:
int16_t samples[(MIN_BUFFER_SAMPLES > avcc->frame_size)?MIN_BUFFER_SAMPLES:avcc->frame_size];

But after that, the audio sync is perfect, and the scene transitions seem to be too!:cool: