Log in

View Full Version : Audio de-sync with multi-part files: how to fix?


belloq
20th April 2007, 16:40
Hi all,

Been lurking around here a while and am relatively new to transcoding from HD sources. I've used a variety of methods to get to where I'm at, but regardless of how I get to this point, the results are the same:

1) m2t (MPEG TS/AC3 mux) stream is split (removing commercials)
2a) Resulting files are joined and encoded into an AVI (let's not bash AVI while we're here...)
or
2b) Resulting files are encoded into AVI separately
3) (from step 2b) Join AVI files with AVI Mux GUI

In step #2, I've used different encoders, but I seem to like XviD or 3viX better. (h264 requires demuxing steps and/or command-line tools which, at least for me so far in my lack of knowledge, gives even worse results.)

The result from step 2a is three or four perfect looking and sounding video files. Audio is synchronized all the way through.

However, the result from Step 2b or step 3 is a great looking file until the first commercial gap. The second part of audio starts de-sync'd from the video.

What I've noticed from step 2b is that the audio in parts 2 and beyond start just slightly delayed from the video. Played by itself, the sync is great.

What seems to be happening is that there is a gap in the audio stream between the end of one part and the beginning of the other. And no matter what method I use to join (join separate TS files, then encode, or encode/join at the same time, or encode separately then join) the joining process is removing the audio gap. It makes sense that the audio stream can't have a gap in it.

My question for all you bright and friendly folks is how to I get this gap preserved? Is there a tool which will join AVI files, reading the audio delay in each file and substituting in silence to keep the audio sync'd? Do I need to use a better tool which will cut the video/audio perfectly with no resulting gap?

Thanks for any help you can provide.

Turtleggjp
23rd April 2007, 16:00
Assuming you are keeping the original AC3 audio, yes this can be a problem. I think the problem stems from the fact that AC3 occurs in 32ms segments or frames. Because of this, it is highly unlikely that your video and audio will have exactly identical times. Either your audio will be shorter than your video or longer. Ideally, it will only be off by no more than a half a frame (16ms) which shouldn't be noticable. However, when you start joing files together, the AC3 soundtracks will be put end to end, which can increase the error factor. In theory, what you would need is to have a gap of silence that is of an arbitrary length to keep the audio in sync. I'm not sure if this is possible with the AVI container, but it might be with another one (I only use AVI myself too). My solution to this problem was a little different.

When I process HD captures, I do not cut the transport stream, since this only gives GOP accurate cutting, and also does some weird things with audio delays. I run my captured files through ProjectX first, which not only demuxes the audio and video, but also does a very good job of handling errors in the stream, and also removes the audio delay. I then index the resulting .m2v file with DGIndex and then open it in VirtualDub. I then edit (frame accurate now) the video and when finished, I save the processing settings giving me a VirtualDub .vcf file that contains a bunch of cut points. I convert these to AVI Synth Trim commands, which then gives me a script that when opened gives a perfectly edited video clip, which can then be encoded to the format of my choice (usually XviD for me). The only thing left is of course the audio. I do not know of any program that will perfectly cut the audio correctly, but I do know one that is close: AC3 Cutter (http://forum.doom9.org/showthread.php?t=92325). By itself, AC3 cutter has trouble similar to what you are experiencing, but I was able to create an Excel Spreadsheet that will figure out exactly which AC3 frames need to be taken from the source in order to make the entire clip stay in sync. Basically, it decides which frames to take for each edit point, but then counts how many video and audio frames have been taken so far. Based on this, it knows how much sync error is at each cut point, and adjusts the next one accordingly. It then gives me what I need to make a .vcf file for AC3 cutter to use with a frame rate of 31.25 (AC3 framerate). As long as it cuts exactly where I tell it to (it does about 95% of the time), the audio stays perfectly in sync. I've even tried it with a sample clip that I cut 20 times! I hope to someday soon modify AC3 cutter's .vcf parsing code to do what my Excel spreadsheet does, so that others can use it too.

I'm not sure what else you have tried, but some of the other methods that sort of worked for me were:

1. Using VirtualDubMod to cut the AC3 (still had sync errors, and often created glitches at the cut points)
2. Creating an AC3 file with a WAV header so that VirtualDub could open it and cut it (at first, no glitches, but eventually started having problems similar to #1).
3. Edit the transport stream and then feed the result through ProjectX before transcoding further (this took care of sync issues, but I was not satisfied with the accuracy of editing).

Good luck, transcoding HDTV is quite a bit more challenging than DVDs.

Matt