X264 video encode: audio going out of sync

moriz

Member
Mar 11, 2009
196
0
0
i'm at my wit's end here. long story short: i record gameplay with DXTORY, audio stays in sync throughout. as soon as i do any form of encoding on it, the audio track plays slower than the video. they'll be in sync at the beginning of the video, and gradually go out of sync. by the end of a 1 hour video, audio's delayed by over a second.

i don't know if this is the right place to ask, but hopefully someone will have experience with it here. here are the mediainfo exports:

original:
Code:
General
Complete name                            : D:\record\bf3 2012-07-17 12-44-02-468.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
Format profile                           : OpenDML
File size                                : 33.9 GiB
Duration                                 : 14mn 32s
Overall bit rate                         : 334 Mbps
Original source form/Distributed by      : Video:YUV420 Audio0:Speakers (ASUS Xonar Essence STX Audio Device) Audio1:Microphone (Display Audio)
Writing application                      : DxtoryCore ver2.0.0.117

Video
ID                                       : 0
Format                                   : xtor
Codec ID                                 : xtor
Duration                                 : 14mn 32s
Bit rate                                 : 331 Mbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 29.970 fps
Bits/(Pixel*Frame)                       : 11.999
Stream size                              : 33.7 GiB (99%)

Audio #1
ID                                       : 1
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : 1
Duration                                 : 14mn 32s
Bit rate mode                            : Constant
Bit rate                                 : 1 411.2 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Bit depth                                : 16 bits
Stream size                              : 147 MiB (0%)
Interleave, duration                     : 999 ms (29.95 video frames)

Audio #2
ID                                       : 2
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : 1
Duration                                 : 14mn 32s
Bit rate mode                            : Constant
Bit rate                                 : 705.6 Kbps
Channel(s)                               : 1 channel
Sampling rate                            : 44.1 KHz
Bit depth                                : 16 bits
Stream size                              : 73.4 MiB (0%)
Interleave, duration                     : 999 ms (29.95 video frames)

encoded:
Code:
General
Complete name                            : C:\Video Output\test.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 224 MiB
Duration                                 : 14mn 32s
Overall bit rate                         : 2 150 Kbps
Movie name                               : test.mp4
Writing application                      : Lavf53.24.0

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3.1
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 5 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 14mn 32s
Bit rate                                 : 2 048 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.074
Stream size                              : 209 MiB (94%)
Writing library                          : x264 core 120 r2120 0c7dab9
Encoding settings                        : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=9 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=4 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=30 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=2048 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=51 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Matrix coefficients                      : SMPTE 240M

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 14mn 32s
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Delay relative to video                  : -2s 2ms
Stream size                              : 13.3 MiB (6%)

relevant computer specs:
i7 2600K at 4.5 GHz
16 GB DDR3-1600 RAM
asus xonar essence STX sound card
GTX 680

thanks in advance.
 

Phynaz

Lifer
Mar 13, 2006
10,140
819
126
What codecs and software are you using?

Whenever this happens it is almost always a codec issue. I'll bet you have lots of different video software loaded, right?
 

moriz

Member
Mar 11, 2009
196
0
0
my workflow is sony vegas for editing, then frameserving it to avsproxy, which goes to avidemux for encoding. i'm using x264 (mpeg-4 AVC) and AAC encoders. and before you ask, if i skip sony vegas, the issue remains.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,250
3,845
75
I thought I remembered something about a number divided by 1001 for this:

framerates are normally written as decimals, such as 29.97fps or 23.976fps, the standards actually call for ratios, like 30000/1001 (29.97) or 24000/1001 (23.976). While they may be indistuingishable from each other to the human eye, these slight differences can cause other software which expects the correct ratio to have problems. When dealing with NTSC video it's almost always best to use the ratios instead of the nearly equivalent decimals. This argument represents the numerator in the ratio (30000 for NTSC or 24000 for NTSC film).

I'm guessing that somewhere the decimal and the ratio are mismatched. This might show a way to fix it without reencoding.
 

moriz

Member
Mar 11, 2009
196
0
0
I don't think any of that are relevant, since I'm dealing with game recordings recorded at exactly 30 fps. Recording and encoding at 29.97fps gave the exact same result.
 

Fayd

Diamond Member
Jun 28, 2001
7,971
2
76
www.manwhoring.com
I don't think any of that are relevant, since I'm dealing with game recordings recorded at exactly 30 fps. Recording and encoding at 29.97fps gave the exact same result.

he's telling you when you try muxing, use a command line argument to set the fps for the video stream at a slightly slower rate, in order to get it still in line at the end.

you should just have a raw videostream and can set its fps however you choose, at this point.
 

takeru

Golden Member
Jan 1, 2002
1,205
3
81
i remember this problem from awhile ago. if its in sync at the beginning and slowly losing sync. try changing the indexing. this is coming from using virtualdub though, so may be different for you, but when i had that issue it was because of the key frame and indexing intervals between the audio and video streams, not really the encoding itself. also i would record at 23.976 or 29.976 if you can instead to match standard framerates.
 
Last edited:

Phynaz

Lifer
Mar 13, 2006
10,140
819
126
my workflow is sony vegas for editing, then frameserving it to avsproxy, which goes to avidemux for encoding. i'm using x264 (mpeg-4 AVC) and AAC encoders. and before you ask, if i skip sony vegas, the issue remains.

Why not just save H.264 from right within Vegas?
 

moriz

Member
Mar 11, 2009
196
0
0
ok, i THINK i've managed to fix it. i looked into the mediainfo output from the original file, and found that the "Interleave, duration" of the audio is set differently than the rest of the video. unfortunately avidemux doesn't seem to have the option to change the indexing. so, i manually set the video framerate to equal the audio, then used a FPS resample filter to bring everything back to 30 fps. everything seems to click back into place now.

the examples i posted in the OP has the video at 29.970 FPS, while the audio "interleave, duration" is set to 29.95 video frames. am i even interpreting this properly?