Past EED rants

Labels

Live leaderboard

Poker leaderboard

Voice of EED

Thursday 17 January 2008

Fixing mp4 audio sync [Spiny]


Fixing audio mp4 sync.Anyone who owns an iPod video or PSP has probably coonverted video to watch on the bus. When converted from another source say avi or flash video (Which the clan approved FreeDownloadManager does very niceley) the audio can go out of whack & by the end of the piece it looks like a badly dubbed karate film.Here's how to fix it. I gleaned this stuff from the interwebs, but if you follow my guide instead of theirs you'll do it in half the time. You'll need Quicktime and the rather excelent VLC Player.1. Find the delay
  • Open the video in In VLC Player
  • Start playing the video & skip to where it starts to go out of sync
  • Then press Ctrl+K or Ctrl+L to adjust the audio delay till it's back in sync. It'll show you the size of your adjustment in the top right of the window
  • Repeat this at a few intervals, making the last adjustment close to the end of the video. The reason for this is that often the audio gets progressively more out of step the further you go through the video, so it's easier to do it a bit at time. When making your final adjustment, note the size of the audio delay you've introduced (measuered in milliseconds)

2. Fix it
  • Open up the video in quicktime
  • Drag the right hand selection marker (the black triangle) all the way to the right.
  • Do Edit->Select All
  • Now drag the right hand selection marker back for the same amount of time as your audio delay. e.g. 3000ms = 3 seconds
  • Do Edit->Copy
  • Do Edit->Add to selection & scale
  • Select Show Movie Properties from the Window menu
  • You'll see the video & audio tracks duplicated. Untick the first audio track and second video track so you're left with the original video track and new audio track
  • Play the file to verify your work
  • Go back to Window->Movie Properties and delete the unused video & audio tracks.
  • Do file->Save As to save your video to a new file

3. Sip Champagne & nibble nachos.By the way if you're still using quicktime to play mov & mp4s, install VLC & use that instead. Or ffdshow & windows media player.

9 comments:


  1. Nice tip Spine. The 360 comes with a nice mpeg4 player now but it doesn't have the sound sync jogging feature that xmbc had, so I shall make use of this tippage. Cheers!

    ReplyDelete

  2. When using VLC to advance to retard the audio on XP the sound mysteriously disappears when the sound interval exceeds 2000 ms. Retarding the delay back to 0 restores the sound.

    Overall I find this process insufferably clumsy. I guess it's OK for some special movies but I just want to lip synch the speakers on Google Tech Talks and it's not worth the trouble.

    Hard to believe this kind of encoding problem even exists - what kind of brain dead programmers would permit two obviously synched streams to drift by three seconds as they convert from one format to another. I'm sure some geek will wax eloquent on this topic but, as Linus would say, he's still ugly and stupid.

    ReplyDelete

  3. Furthermore, the proposed solution doesn't work well. When I attempt to reduce the sound by three seconds the actual reduction is over seven seconds. That appears to be the granularity limit of Quicktime Pro when dealing with a 1:23 file. So I have a choice - the sound can be three seconds advanced or three seconds delayed. Sucks either way.

    Your non-solution just cost me $34. Thanks.

    ReplyDelete

  4. Hmm, not sure why that would be. Presumably it plays OK when you select the 1st video stream and 2nd audio stream (or vice versa) as selected in Movie properties?

    Here is the original article i gleaned most of the info from, although it's a bit more trial & error as it only uses quicktime (which can't show you the absolute value of the audio delay). Hopefully I've just got something ass backwards in my explanation above.


    ReplyDelete
  5. This is how I ended up making it work. Mind you, in my case the problem is a sound track that starts in sync and ends up out of sync by some number of frames. This doesn't treat the problem of a shift that is constant, start to finish. The solution to that seems obvious but I'm not going to discuss it here.I do the whole time stretch operation including delay analysis with QT Pro 2.7 running on XP. I find a point close to the end of the video that allows me to determine the delay interval. I usually find a spot where the speaker's lips stop moving and the audio continues (or vice versa). I change the interval counter at the lower left from time to frames by click and select on the arrows to the right of the interval box. I then note the frame counter when the lips stop moving. I advance frames until the speaker's voice stops and subtract to get the number of frames I need to delay. In my example case it is 134 frames. Note that the same method works when the audio is behind the video. Time from the cessation of audio until the speaker's lips stop moving. I select all and then click on the right hand selection market. It turns dark. I then use the left arrow key to back up the right selection marker 134 frames. A frame view gives far better visible granularity since there are many frames per second and the time view only resolves to seconds. Next I copy the selection. The copied selection is now the desired number of frames shorter than the total selection. Here's the step that's missing above - I select all again. I want to stretch and paste the shorter section onto the complete video. Maybe that's so obvious it doesn't need saying but if I don't select all again I will be stretching and pasting onto the same selection I copied. That doesn't do much good, obviously. Next I add to selection and scale. This stretches the copied selection appropriately. I then go to the Movie Properties window and try playing both new combinations - Video One Audio Two and Video Two Audio One. One of these will be synched up and the other will be twice delayed. Easy to find the right one. I delete the worthless audio and video streams. Save will create a .mov file but if I start with an .mp4 I usually want to end up with one. To do that I must use the export entry in the file menu and pick the .mp4 format. The QT Pro export codec is insufferably slow for a video of any length. I start it at night and let it go. Unfortunately, the .mp4 created by QT Pro does not play on my PSP even though it plays fine on a PC. My solution was get the PSP Media Manager from Sony for $17. I now use QT Pro to save the time corrected .mp4 file as a .movie which is then converted to .mp4 by PSP MM. The conversion turns out to be about three times faster than using QT Pro export. A fringe benefit is that PSP MM runs fine in the background. QT Pro tends to make my system almost useless when it is exporting an .mp4.The good news is that this works. The bad news is that it's still time consuming and boring. For the odd film it's worth the effort. I tend to throw heavy objects around the room when sound gets out of sync with video on something I really want to watch. Many of the Google Videos I have downloaded have a sound track that gets several seconds out by the end of the video.Another benefit from buying the PSP Media Manager is that it converts .avi files to .mp4 if one installs the Divx codec (available as a free download).Thanks for the above information. It got me three quarters of the way there and I'm now happy to have QT Pro having found a way to make things work.Best regards.

    ReplyDelete

  6. Hold the presses! Now for the clincher.

    I start with a three second delay and correct it with QT Pro as described above. I know it is corrected because I play it back on QT and observe lip sync at the end of the movie. I then convert and download the file to PSP using PSP Media Manager. The Sony PSP Media Manager conversion creates an .mp4 from the .mov with a new audio delay even worse than the one that I corrected!

    This situation is even uglier and stupider than I thought.

    It would seem that the audio and video streams are converted without any attempt to keep them synchronized via embedded time markers.

    Perhaps the QT Pro export facility does the job right but that doesn't help because the .mp4 it creates is not recognized by my PSP as a video file.

    The problem with computers is that as they become commodities the engineering becomes increasingly stupid. Hey, can Joe six pack even tell that the lips are three seconds out of sync with the audio?

    I'm throwing in the towel here. I originally got the PSP as a way to view pictures from my digital camera. The video feature was nice but not important. Then I got sucked into this fiasco because I discovered Google Video and started downloading badly synched lectures.

    The fact is that Google Video is probably going to be wrapped into YouTube and I doubt seriously that YouTube is going to allow downloads. So I'm pissing my time away trying to solve a problem that will probably become irrelevant in six months. It also appears the problem is intrinsic to the conversion process. What a waste of time.

    You may wish to verify my results and, if you find them true, let other poor slobs know what a hopeless job they are undertaking.

    I'm outta here. Good luck.

    ReplyDelete

  7. A further discovery.

    It turns out that if you are lip synching an .mp4 file that already plays on the PSP, the right way to export and save the .mp4 is by selecting MP4 file format and PassThrough video format in the export box.

    QT Pro adjusts the video frame rate to synchronize with the audio. My adjusted video has a frame rate of 29.97 fps vs: the normal 30 fps. This is how it "stretches" the audio track to make it fit. The audio is set to 44 khz and it's not feasible to change that sampling rate. The only other possibility is to change the frame rate of the video.

    The way to preserve this frame rate change is by using the "passthrough" option which bypasses all the compression algorithms and basically just copies the .mov to an .mp4 with minimal processing. I don't need downsizing anyway because my videos have already been compressed. I'm just adjusting the frame rate by a tiny bit to make it sync right with the sound.

    A big bonus here is that the QT Pro conversion process for an hour movie is about five minutes vs: two hours before.

    The resulting .mp4 is synched correctly and plays perfectly on the PSP!

    ReplyDelete

  8. Cor, well done. They don't make this stuff easy eh?

    ReplyDelete
  9. hey, can i get one of you to sync some movies for me?...please? my mythbusters eps' are wack...help someone. i will give you $500 Give you my email....small_fry-big_chips@hotmail.comor someone could give me a really easy way to do this.......

    ReplyDelete