Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > Capturing and Editing Video > New and alternative a/v containers

Thread Tools Search this Thread Display Modes
Old 1st May 2016, 20:51   #1  |  Link
Registered User
Join Date: Oct 2013
Posts: 1
MPEG terrestrial broadcast to MP4 conversion - irregular audio desync

You'll see this is my first post so you'll excuse me if it's not in the right place. Unlike all those people who are (thankfully) put off by the delay between registration and first posting,sparing us all the spam from those guys who are too stupid or lazy to search for answers to their "can't play my vidz. Plzz hlp. K thnx in advance" questions, I wanted my first post to be a solution to a problem. So my heart's in the right place even if this post isn't. While I don't imagine many people will have this problem in future I hope this will help if anyone does since I imagine there are still a few mpegs floating around.

The problem was desync between audio and video when transcoding from MPEG to anything else. My target file was mp4. The desync was neither progressive nor constant but unpredictably variable. The desync wasn't present in the any of the various intermediary files, all containing MPEG streams, but was present in all (except maybe one) transcoding attempts before a solution was found. I can't say anything meaningful about the cause other than that it had to do with overhead in the container file which may have been introduced when converting between various container files. Unless you want the history, I suggest skipping down to the "The Solution" section where I've given it it's own little heading so you can find it easily.

A few years ago I had to transcode a terrestrial broadcast of a dramatic work for educational purposes (which was covered by the licensing scheme of the institute where I was employed so this was a legal copy). Unfortunately, until finding the solution, all attempts to convert this file to a reasonable size for storage on the institute's miserly allocated storage space failed due to an irregular (not progressive) and very noticeable audio desync.

The recording was made using Windows Media Centre to the WTV container. WTV is a direct stream copy. IIRC, at the time there were few broadcasters using H.264 vide and most used MPEG. In this case the broadcast stream was MPEG-2 vide with MPEG-1 Layer 2 audio.

WTV replaced the DVR-MS container and this annoyed a lot of people. Automated tools that worked on DVR-MS didn't work on WTV. However, Windows included an inbuilt function that would convert WTV files to DVR-MS. This function only worked on MPEG streams. WTV containing H.264 streams resulted in an error.

Regardless of content, many common video editing tools wouldn't recognise WTV or DVR-MS files. But using existing tools it was easy to again change containers from DVR-MS to MPG. The conversion from WTV was DVR-MS was entirely lossless including retaining all the broadcast metadata (like broadcast time, plot synopsis, subtitles). Similarly the DVR-MS to MPG, while losing the metadata, was lossless for vide and audio.

One of my many failed encodes I examined more carefully than the others. Here I'll list the video time and the audio lag in frames (at 25 fps).

2:19, 20
9:13, 18
15:57, 6
45:00 roughly in sync
50:22, 4
74:34, 4
89:43, 5

I can be that precise as at those times there was something dropped to the floor, or a door slammed, or someone slapped someone else, and the impact was visible on screen. That is from a very noticeable 160 to an almost painful 800 ms delay. When I trimmed the video to remove the end of the earlier show the desync was worse.

Numerous programs were tried for encoding and muxing including:
avidemux, virtualdubmod, handbrake, ffmpeg, mkvtoolnix, yamb
I tried many other programs whose names I no longer recall since I downloaded them, converted with them, found the desync was still around, and deleted them

I tried several compression formats including:
H.264, H.263, H.262, huffyuv
at various average bitrates or rate factors
figuring encoding at very high rate bitrates for something other than H.264 then transcoding to H.264 would reduce the generational loss and would at least let the file be compressed

And several audio formats:
cbr mp3, vbr mp3, cbr AAC, vbr AAC, WAV
at various bitrates

And several container files:

Sometimes encoding the vide and audio at the same time, sometimes encoding them separately then muxing them. I really thought that an independent cbr mp3 muxed with H.264 video would prevent desync.

Curiously, and very annoyingly, the vide and the audio streams reported durations that were the same to within a few ms yet when muxed always failed to sync. Except possibly for one time.

I had, much earlier, apparently made a small version so an lecturer could watch it on a portable device. This contained H.264 vide and AAC-LC audio. I guess, since nothing seemed wrong with the file, I paid no attention to it. I had no idea of the program used or the settings applied. It was only when drive space became an issue that I tried to compress the source for archiving. I examined the portable file itself but it only reported standard metadata like crf 23 and ref frames 1 and b-frames off etc.(ipod compliant) which I replicated but this didn't help at all.

I had tried converting the MPG file with MPEGstreamclip but this was unacceptably slow as it was going to take about 9 hours and was running at only a fraction of the speed of other transcoders on videos of the same resolution. Computers were switched off overnight so the encode would have been ruined and I couldn't tie up a machine all day on one little job when there was a rush on reducing file storage and several other encodes to run.

However, for some reason I used MPEGstreamclip's convert as "MPEG with MP2 Audio" option. This was a lot slower than say, saving a video to a different container without transcoding using avidemux but a lot faster than any transcoding job I ran on the same size vide so I don't know what was going on except to say it wasn't transcoding the vide.

This resulted in yet another MPG file (again with audio synced like all the MPEG containers before it) but this one, when compressed with Handbrake, resulted in an MP4 file which retained sync.

The workstream is something like
A) recorded file MPEG in WTV using Windows Media Centre
B) changed WTV container to DVR-MS using inbuilt Windows tool
C) changed DVR-MS container to MPG using some program I forget (maybe MPEGstreamclip)
D) "converted" MPG to MPG using MPEGstreamclip
E) transcoded to mp4

When I compared the files at step C and D using MediaInfo I found these differences.

		Original MPEG	"MPEG with MP2 Audio"
Total		3489		3419			kbps
Video		3164		3095			kbps
Max bit	rate	15		(absent)		Mbps
Audio delay	-467		-11			ms
Menu header	(present)	(absent)
(absent) means the stat was not reported, it does not mean the value literal was "(absent)".

The second file was correspondingly smaller (about 50 MB) as the bitrate suggests. You'll note that the total video rates differ by 70 while the video rates differs by 69. I think this is just rounding (total is based on audio + video and we're only seeing four of seven sig figs) and the audio stream was unchanged at around 69 or 70 kbps (or around 64 kpbs and the other 5 or 6 kbps is overhead of some kind). Despite the different audio delays, both files had good sync.

This was repeatable, but only on the same file. I had no other file presenting the same audio mess so I can't say if it will work for others but maybe others more knowledgeable have some insight. I can't provide any more details as these are all the notes I have, made for my own use in case I encountered the same problem but I haven't, and I've since left that workplace.
Myeong is offline   Reply With Quote

mpeg/avc, sync audio and video, windows media center, x264

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 16:10.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.