Over the past several months, I've been working on techniques to ensure A/V synchronization of captured HDTV Mpeg2 Transport Streams. It is time consuming and frustrating to convert an hour long TV program from 1080i to 720x480, only to end up with portions of the program completely out of A/V sync. I have a MYHD MDP120 OTA capture card, but this process should work on most .TP or .TS files.
Two factors are primarily responsible for audio and video going out of sync - 1) Bad Reception and 2) AC3 file format changes between commercials and the main TV program.
-Bad Reception- (aka -The 'Tisk' Factor)
I call this the Tisk Factor because of the terribly annoying 'tisk' sound you'll hear when digital program reception is interrupted. Obviously, a well located antenna will reduce the Tisk Factor significantly, but it is difficult to eliminate this phenomenon completely. On windy days and evenings, digital OTA reception can be less than stellar.
-AC3 File Format Changes Between Commercial and Main TV Program-
One of the cool things about OTA HDTV in the US is that the main program's sound is broadcast in 5.1 384kbs. However, on many channels, commercials are broadcast in 2.0 sound and at a different bit rate than the main show. This situation creates audio sync problems when you convert your 8GB HDTV file to a 1GB (or smaller) Standard Def DVD or XVID file.
Many folks try to cut out the commercials from the Transport Stream file using programs like MPEG2VCR, HDTVtoMPEG2, etc with varying degrees of success. Sometimes the resulting file syncs up well, but not always. I've tried the majority of them, and unfortunately none could maintain perfect sync on a badly formatted transport stream file every time.
-Software to the Rescue-
The trick is to create a "fixed" Mpeg2 program stream file, devoid of the Tisk Factor, and to fix the AC3 file so the audio doesn't go out of sync due to bit rate changes. You'll need 3 programs to do this. Fortunately, they are all free (Note: if you want to do this with commercial software $50, VideoRedo will perform the steps below, all in one package, and it accurately cuts out commercials - Convenience vs Cost)
"This program arose out of my inability to encode to my format of choice, recordings I made off of some stations due to the fact they change the audio bitrate during commercials. This program has solved my problems and I hope some of you guys find it as useful as I have."
ProjectX - (Download the 'Compiled' version so you won't have to install Java on your PC - here's the URL for this version (25Mb in size): http://download.videohelp.com/~download/ProjectX_09.3.0.zip )
ProjectX is outstanding at maintaining A/V sync when demuxing a transport stream file. It is a mandatory app if you work with HDTV TS files.
Mpeg2Repair - http://users.adelphia.net/~mwilczyn/mpeg2repair/mpeg2repair.zip
1) If the Transport Stream file won't play in Media Player/Classic or freezes during playback, you'll want to run it through Mpeg2Repair as the first step. This will cut down the time ProjectX takes to demux the transport stream file. This step CAN be skipped if you're certain your capture was free of the 'Tisk Factor'.
2) Load the file into ProjectX and demux the .TP/.TS file into an .M2V (or .MVP - same thing, just different extensions) and an .AC3 file. This will take some time if the file has errors in it. This is where ProjectX really shines. It will ensure the sync stays 'perfect' in the resulting M2V and AC3 files. This process can take a while. I've scripted the demuxing by using ProjectX from the command line, and I'll post the syntax if anyone requests it.
3) Run AC3 Cutter on the demuxed AC3 file. Although ProjectX will fix 99% of the problems, the other 1% will be fixed by AC3 Cutter. This is a command line app - very easy to run. Syntax is AC3Cutter source.ac3 target.ac3
-The Final Steps-
Re-encode your demuxed .M2V file with your favorite app
Mux your target.ac3 file to your re-encoded Mpeg or AVI file
Use your favorite editing app to cut out the commercials.
Voila ! - A great looking, great sounding final product.
Addendum:Taking out the commercials before encoding is a good idea, and I've been doing it as the norm to speed up my encodes. You'll need some free disk space - three times the size of your original Transport Stream file, as you'll be creating some temporary files which will serve as the input file for the next step in the process. By the time you try this the second time, you'll be able to do it in your sleep. We add a utility to the ones above to quickly cut commercials - Mpg2Cut2 - this app is truly great for cranking through a file and yanking out the commercials. Here's the application path -
PROJECTX - (convert to m2p option) - that's just an .MPG file with a different extension, the file is identical to an Mpeg2 file
MPG2CUT2 - open the .M2P file, cut out the commercials
PROJECTX - demux the now commercial-free file into a .M2V and .AC3 file - this step is important, as ProjectX does a masterful job of maintaing audio/video sync.
Finally, take that .M2V file, re-encode it, mux in the .AC3, add butter, and you're done !
+ Reply to Thread
Results 1 to 30 of 58
Originally Posted by Soopafresh
Note: Use the following version of ProjectX -
Here's a command line example:
"C:\Program Files\ProjectX\projectx.exe" -o d:\demuxed -n capture1 -i 0x11,0x14 d:\tsfiles\capture1.tp
The above line says "Run Projectx.exe, output directory will be d:\demuxed, output file names will be capture1.m2v and capture1.ac3, demux transport stream PIDs 11 and 14, and the source file name is capture1.tp".
You can find the PIDs by loading the source file in Mpeg2Repair, and pressing the "Find PIDs" button, or from the command line, you can run DGtable capture1.tp . DGtable can be found in the following Zip file: http://neuron2.net/dgmpgdec/dgmpgdec130.zip
Great simple method here Soopafresh, what do you suggest for encoding video though. I have been trying virtualdubmod, with xvid 2500 bit rate
deinterlace (a 1080i at least)
and resize it to something like 1280x720 or something smaller like 854x480 or something
But with this combo, I am not impressed compared to the original.
Are there any other filters I should use to keep the quality?
You'll get the best quality by far if you use AviSynth, but you'll have to learn some of the scripting commands. Nonetheless, it's a tremendously powerful application.
First, get this aspect ratio calculator - it'll simplify so much when you decide on the dimensions to resize your video.
If you use VirtualDubMod or VirtualDubMpeg2, there are many excellent
plugins. What looks good for me might not look good for you, and vice-versa. The ones I use most frequently are:
MSU SmartSharpen http://www.compression.ru/video/smart_sharpen/index_en.html
Shadow Smoother http://timsara.zetafleet.com/vdub/ss/shadowsmoother07.htm
Also, try some higher bit rates for testing purposes.
Thanks soopafresh, I have got the demuxing, getting the final product in sync, but it just the picture doesn't look all that great. Do you have the avs script you use for your combination.
In my experience there's not a whole lot needed avs script wise for HD. These are the two scripts I use:
For 720p sources:
MPEG2Source("...") SelectOdd().Decimate() Crop(...) LanczosResize(1280,720) ConvertToYUY2()
MPEG2Source("...") Telecide().Decimate #if going to < half 1080i res use ReduceBy2().Decimate() instead Crop(....) LanczosResize(1280,720) ConvertToYUY2()
Also, the links to AC3 Cutter and AC3CGUI were changed last week as the old hosting plan was about to expire. The new link for both programs is: http://ac3c.vidphiles.com.
Thanks for the info, GaveUp. I made the corresponding changes to my previous posts.
WOW....SUPER SUPER THREAD !!!!!!!
I am so happy right now, I can do back-flips and cartwheels here at work and not care
I just got into the HD game with essentially the same card as Soopafresh MyHD MDP-130. SO this topic is right on the money for me.
One thing tho, for GaveUp with your AVISynth script.
Why use ConverttoYUY2?
If you are converting your HD 2 DVD with lets say CCE, should you not leave that script line off or use converttoYV12 (original HDTV format ?).
If TMPGEnc it should be ConverttoRGB24?
Also, YUY2 script line should be used when doing DivX, XviD in Virtualdub/VDMod, or WMV conversion right?
Thanks look forward to your answers.
Avisynth 2.5.x's default colorspace is YV12. It's in my scripts because I go to 720p XViD's and Virtualdub does not properly handle YV12 (in some cases you'll get green bars on left and right of the pic ... entirely unrelated to the ABC greenbar). IIRC, CCE didn't like YV12 last time I checked either, though, that may have changed. Suffice to say it is safe to leave it off, but if you get the green bar effect try it and it very well could solve the problem.
One thing worth noting is that if you are going to convert HD to DVD format or similar you should probably do a color conversion as the color on NTSC is different over HD. I don't remember the name of the AVISynth filter off hand but I believe it was trbarry that wrote it. Really, though, if I were going to DVD I'd change a bit more in those scripts in the interests of speed. One thing is you can replace Telecide().Decimate() with ReduceBy2().Decimate() for 1080i. You can end up with dupe frames left in, but for me I don't notice any stuttering from it so I don't mind it for the speed boost. Some people might, though.
Also, as far as cutting commercials with PX, I wouldn't. Cutting with PX isn't frame accurate so you'll with ugly, abrupt, cuts if the GOPs don't end at the right spots (end of black before commercial and last frame before black of fade in from commercial).
Originally Posted by GaveUp
I'll go over to doom9.org to check out the tbarry color conversion thing. IRT, the dupe frames thing, should I just leave the script as Telecide().Decimate() as speed would not be a big deal for me (within limits of course), as I just want the best possible conversion? As the dupe frame thing may pop up and want to avoid that. Also thinking of including IIP in my script. Sloooooow as all get out, but great. We'll see.
Yes. If speed isn't an issue you would be better off using Telecide().Decimate().
Hey DVWannaB - IIP is pretty amazing, but too slow for HD material. Until Didee comes out with his Crystality Sharpener, try LimitedSharpen.
Originally Posted by GaveUp
Originally Posted by Soopafresh
Originally Posted by GaveUp
Question for you or anyone else who knows. What I am noticing with my HD caps is that some shows I know for a fact were originally done in 23.976 fps progressive, but are being broacasted as 1280x720p 59.94fps or 1920x1080i 59.94fps.
If I wanted to restore the 23.976 fps in my DVD encode how will the script above change/added? Also how do you all handle interlaced pattern breaks during commercials? Many thanks.
Originally Posted by DVWannaB
ok, so if the original format is in 29.97fps, like say a Football game, but broadcast in 1280x720p or 1920x1080i 59.94fps, do I drop decimate() from the script since in that case I dont want to go to 23.976?
Sorry for the million & one questions, just trying to get a handle on what the heck I'm doing here (darn noobs)
It depends. As an example I'll use Survivor. It's shot NTSC and upconverted to 1080i so you would expect that leaving it at NTSC framerate would be the best. This isn't the case, though. After taking a closer look I realized that the material was, in fact, IVTC'd. The only conclusion I can come up with is that they deinterlace it at the station, IVTC, and upconvert and telecine. The moral? You need to check the caps to see if it is telecined or not. The best suggestion I can give is that it seems to be station specific. All the stations around here do the process I've described above, but from other people I've talked to this isn't a universal thing.
Hey nnigam - see the addendum added to the top post - I added some steps to cut out the commercials before encoding. There's probably a better way, but it works for me.
Originally Posted by Soopafresh
>>I have been trying to encode and burn a DVD of a 2 hour HDTV capture of a NOVA program for nearly a week. I capture using capdvhs following the guide posted on the avsforum. I have also used HDTV2MPEG and VideoReDo. I have run the quickstream fix but not only didn't it fix the problem I lost audio. I have tried NVE, and HDTV2DVD with the same results. I get a series of pixillations and skipped segments towards the end of the DVD. I have tried re-capturing the .ts file to no avail.
I destroyed a Logitech cordless optical mouse this evening whilst trying to coax the encoding process which had stalled. The Cat is concerned about my spontaneous outbreaks of cursing and flinging screwed up DVDs hither and yon.
MPEG2REPAIR found 299 errors on first run. All kinds of errors.
Any suggestions are GREATLY appreciated!
Originally Posted by GaveUp
PEG2Repair: C:\Documents and Settings\Merlin\Desktop\New Project\Einstein's Big Idea.ts
Sequence Frame 94890(2-I) / Time 0:52:46 :
Error: Packet 28956653 has no TS Sync Byte.
VideoWarning: Discontinuity of (8+) packet(s). First packet ending at offset 5448910596
VideoWarning: Discontinuity of (13+) packet(s). First packet ending at offset 5448911536
VideoError: Slice 64 followed by invalid slice 22. (Should differ by one row)
AudioError: Corrupted AC3 frame of 3046 payload bytes at file offset 5444559258
VideoError: Invalid macroblock address increment code. MBA=7615(880,1008)
VideoError: Missing 546 macroblocks in picture slice(s) at MBA=7614(864,1008).
FileInfo: Last video errors span 62009 bytes at file offset 5444611223
Sequence Frame 94891(0-B) / Time 0:52:48 :
AudioWarning: Timestamp gap of 2.528000 sec. ending at file offset 5448961026
Sequence Frame 94905(13-B) / Time 0:52:49 :
VideoWarning: TemporalRef gap of 1011. Timestamp gap of 0.066733 sec. ending at file offset 5444512632
Sequence Frame 94920(13-B) / Time 0:52:49 :
VideoWarning: TemporalRef gap of 1021. Timestamp gap of 2.402400 sec. ending at file offset 5448976520
VideoWarning: TemporalRef gap of 1. Timestamp gap of 0.033367 sec. ending at file offset 5449145908
Sequence Frame 98373(5-P) / Time 0:54:44 :
Error: Packet 30020679 has no TS Sync Byte.
VideoError: Invalid Huffman code in non-intra MPEG2 block. MBA=1298(1568,160)
VideoError: No start code at end of slice. MBA=1298(1568,160)
VideoError: Failed to decode macroblock at MBA=1298(1568,160)
VideoError: Missing 6863 macroblocks in picture slice(s) at MBA=1297(1552,160).
FileInfo: Last video errors span 11 bytes at file offset 5648936757
Sequence Frame 98374(5-P) / Time 0:54:44 :
Info: End of sequence: 1920 x 1080, 29.97 fps, 12.99 Mbps.
Info: Found 98374 video frames since start of sequence.
Info: 2 video frames found with errors.
Info: 1 audio frames found with errors.
Info: 62019 corrupted video bytes in file.
Info: 2.502500 seconds of video timestamp gaps.
Info: 2.528000 seconds of audio timestamp gaps.
End of Log
I love this thread, it is actually in my Favorites as I don't do a bunch of conversions and forget the steps sometimes. Question, why did you leave out the AC3Cutter repair in the addendum? Does MPG2Cut2 work that good? If so I will have to try that method as my old work flow was the original set doing the cutting and demuxing with ProjectX.
Mpg2cut2 does work quite nicely. What I like most about it is the speed at which you can scrub through your file. Of course, you'll have to try it out and see if you like it. I usually just cut portions of the show and save each segment to file A.mpg, B.Mpg, etc, then load them all in ProjectX and have X demux it all into one .M2v and one .ac3. All of this stuff is so subjective
You're probably right, it never hurts to run the AC3 through the AC3 fixer app, and I had to do just that the other night with a bad reception capture.
akwolf - gaveup's answer is the same as mine. Run the file that you fixed in Mpeg2Repair through ProjectX. Use the DEMUX choice - that function will fix additional errors, but most importantly, it will keep your A/V in sync.
Make sure you install the ProjectX listed above so you can bypass the JAVA install.
You can then Remux your .M2v and .Ac3 with Mplex, which can be found at:
That's one of the few Mpeg2 Muxers out there than can do HDTV resolution.
You want to choose the "Mpeg2" muxing option and a Mux Rate of 0 so the app can determine most of the specifics to properly mux your files.
A lot of steps, huh ? Sometimes drastic measures must be done on the troublesome files.
Oh yeah, make sure you have a lot of free disk space for all of this
From the sounds of it remuxing does not need to be done as he seems to want a DVD and since you author dvds with seperate assets you might as well leave the things demuxed.
Also, I'd say run the file through ProjectX INSTEAD of Mpeg2 repair. The reason being is that I've found Mpeg2 repair can cause some rather annoying video issues due to the way it fixes things. Granted, ProjectX has its own set of quirks fixing video issues, but I find PX's methods to be a lot less disruptive than Mpeg2 repair's.
I failed yet again yesterday with this capture! I work the next three days and will try what you all suggest on Monday. THANKS TO YOU ALL! I really appreciate your help!
I think I'll leave the PC alone tonight though. My boss called me in early today stating he had "lost everything". I was following along listening to him tell me about going to print a document and having the server freeze up. It started getting interesting when he told me "And then the were these really neat swirling colors on the screen!" How a app freezing up on a server can blow away an entire profile on a client is one they didn't cover in my classes...
I wish I could blow 5K on a new box!