View Single Post
Old 1st November 2008, 18:38   #1  |  Link
cengique
Registered User
 
Join Date: May 2007
Location: atlanta, GA, USA
Posts: 14
lost audio sync after merging raw AC3 ripped from DVD and video encoded in H.264

Hi,

I have a PAL-encoded DVD that I want to compress and keep on my htpc hard disk. I followed the mencoder-mp4box-mkvmerge path to compress the video to H.264 with x264 and kept the AC3 audio intact. However, in the muxed MKV file, the audio keeps drifting. I tried changing audio frame duration, sync and delay options in mkvmerge to no avail. I hope somebody can spot some obvious mistake I am making.

Here's how I did it:
Code:
# compress video
mencoder dvd://1 -dvd-device /media/cdrom  -ovc x264 -nosound -x264encopts subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid:weight_b:crf=22:threads=2 -of rawvideo -o rip.h264

# put raw video in MP4 container
MP4Box -add rip.h264 rip.mp4

# dump raw AC3 audio to dump.stream file
mplayer dvd://1 -dvd-device /media/cdrom -dumpaudio

# rename audio file and mux into MKV container
mv streamp.dump streamp.dump.ac3
mkvmerge -o rip.mkv stream.dump.ac3 rip.mp4
Resulting MKV looks like this and has a drifting audio sync problem. Even if I put a fixed delay it keeps missing sync:

Code:
$ mkvinfo rip.mkv
+ EBML head
|+ Doc type: matroska
|+ Doc type version: 1
|+ Doc type read version: 1
+ Segment, size 736098744
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4027)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v0.7.7 + libmatroska v0.8.1
| + Writing application: mkvmerge v2.0.2 ('You're My Flame') built on Jul 16 2008 20:03:58
| + Duration: 5533.120s (01:32:13.120000000)
| + Date: Mon Oct 27 15:02:39 2008 UTC
| + Segment UID: 0xde 0xe3 0x52 0xab 0xac 0x71 0xbf 0x1b 0xbe 0x5c 0xae 0xdd 0x70 0x30 0x76 0x35
|+ Segment tracks
| + A track
|  + Track number: 1
|  + Track UID: 3719640652
|  + Track type: audio
|  + Enabled: 1
|  + Default flag: 1
|  + Forced flag: 0
|  + Lacing flag: 1
|  + MinCache: 0
|  + Timecode scale: 1.000000
|  + Max BlockAddition ID: 0
|  + Codec ID: A_AC3
|  + Codec decode all: 1
|  + Default duration: 32.000ms (31.250 fps for a video track)
|  + Language: und
|  + Audio track
|   + Sampling frequency: 48000.000000
|   + Channels: 6
| + A track
|  + Track number: 2
|  + Track UID: 2748424880
|  + Track type: video
|  + Enabled: 1
|  + Default flag: 1
|  + Forced flag: 0
|  + Lacing flag: 0
|  + MinCache: 1
|  + Timecode scale: 1.000000
|  + Max BlockAddition ID: 0
|  + Codec ID: V_MPEG4/ISO/AVC
|  + Codec decode all: 1
|  + CodecPrivate, length 42
|  + Default duration: 40.000ms (25.000 fps for a video track)
|  + Language: und
|  + Video track
|   + Pixel width: 720
|   + Pixel height: 480
|   + Interlaced: 0
|   + Display width: 768
|   + Display height: 480
|+ EbmlVoid (size: 1024)
|+ Cluster
Note that the frame durations are different for the video and AC3 tracks. The video is correct at 25 FPS from the original (or copied) PAL-format DVD. I'm not sure about the audio frame duration. I tried forcing the MKV to have both of them at 40ms, but it messed up the audio sync further.

I'd be happy to give more info. Anybody have any clues for me?

Thanks in advance.
cengique is offline   Reply With Quote