Log in

View Full Version : iPod Conversion with DGIndex, AviSynth and FFMPEG produces bad audio sync


ScootyPuffJr
25th January 2007, 02:57
Hello Eveyone.

I’m trying to encode some TV Show based DVDs that I own to my iPod using DGIndex, AviSynth and FFMPEG. I’ve tried several of the ‘quick’ conversion programs, but I haven’t had great results (a lot of audio sync problems) and they seem to rely on AviSynth anyway, so I’d like to understand it better, if nothing else to troubleshoot other application problems. I’ve been reading a lot over the last few months, but a lot of it is over my head and I don’t think I’m putting the nuggets together very well. I’ve had some luck, but very often I have audio sync problems, so I’m hoping someone can steer me in the right direction.

The television shows are both new (last 3 years) and older (1970s/1980s). I would expect them to be 30fps, especially the older ones. The d2v file reports that they are 99.73% FILM. Looking at the ripped VOBs with a basic avs script shows the standard 3-progressive/2-interlaced frames. If I ForceFilm or IVTC with Telecide/Decimate and process with FFMPEG the audio drifts out of sync. If I just use Telecide in the avs with no decimate the audio stays in sync.

Is this a case where DGIndex is just getting confused and reporting the wrong source, and I should be treating the video as 30fps, or am I doing something wrong in the avs script processing or ffmpeg encoding, or both?

Thank you in advance for any help you can provide to this confused noob.

------------------------------------------

Here is my process:

1) Rip the DVD using DVD Decrypter.
I rip only the video track and single audio track that I want to encode. I have done it both manually and using the following command line.
DVDDecrypter.exe /MODE IFO /SRC E: /DEST "D:\Video\iPod" /DIRECT 0xE0 0x80 /SPLIT NONE /START /VTS 1 /PGC 1 /CLOSE

2) Create a test d2v file using DGIndex honoring pulldowns with no audio.
DGIndex.exe -IA=3 -FO=0 -OM=0 -DSD=0 -DRC=0 -DSA=0-AIF=[D:\Video\iPod\file.VOB] -OF=[D:\Video\iPod\file] –EXIT

Check the d2v file – most all look like this and show the standard 3-progressive/2-interlaced frames when looking at them with a basic avs script.
Stream_Type=1
MPEG_Type=2
iDCT_Algorithm=3
YUVRGB_Scale=1
Luminance_Filter=0,0
Clipping=0,0,0,0
Aspect_Ratio=4:3
Picture_Size=720x480
Field_Operation=0
Frame_Rate=29970
Location=0,0,0,E98E5
FINISHED 99.73% FILM
3) Encode using Force Film.

A) Create a new d2v File (with audio)
DGIndex.exe -IA=3 -FO=1 -OM=3 -DSD=0 -DRC=0 -DSA=0-AIF=[D:\Video\iPod\file.VOB] -OF=[D:\Video\iPod\file] –EXIT

B) Use the avs script
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\dgdecode.dll")
video = mpeg2source("D:\Video\iPod\file.d2v")
audio = WavSource("D:\Video\iPod\file.wav")
AudioDub(video, audio)
BiCubicResize(336,252)
Crop(8,6,-8,-6)
** This script shows the same 3-progressive/2-interlaced frames sequence when viewed in VirtualDub, even though the d2v was created with ForceFilm and shows Frame_Rate=23976.

C) Encode with FFMPEG
ffmpeg.exe -i "D:\Video\iPod\file.avs" -y -bitexact -vcodec h264 -b 768 -bufsize 768 -coder 0 -vlevel 13 -g 250 -4mv -mbd 2 -trell -cmp 3 -subcmp 3 -mbcmp 3 -s 320x240 -r 23.976 -qmin 22 -qmax 22 -f mp4 "D:\Video\iPod\file.mp4"

The resulting file is significantly out of audio sync.
4) Encode using IVTC/Decimate.

A) Create a new d2v File (with audio)
DGIndex.exe -IA=3 -FO=0 -OM=3 -DSD=0 -DRC=0 -DSA=0-AIF=[D:\Video\iPod\file.VOB] -OF=[D:\Video\iPod\file] –EXIT

B) Use the avs script
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\dgdecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\it.dll")
video = mpeg2source("D:\Video\iPod\file.d2v")
audio = WavSource("D:\Video\iPod\file.wav")
AudioDub(video, audio)
AssumeTFF()
Telecide(guide=1,post=2,vthresh=26)
Decimate() / Decimate(cycle=5)
BiCubicResize(336,252)
Crop(8,6,-8,-6)
** This script shows all progressive frames and has audio sync in VirtualDub.

C) Encode with FFMPEG
ffmpeg.exe -i "D:\Video\iPod\file.avs" -y -bitexact -vcodec h264 -b 768 -bufsize 768 -coder 0 -vlevel 13 -g 250 -4mv -mbd 2 -trell -cmp 3 -subcmp 3 -mbcmp 3 -s 320x240 -r 23.976 -qmin 22 -qmax 22 -f mp4 "D:\Video\iPod\file.mp4"

The resulting file is again significantly out of audio sync.
5) Encode using IVTC only.
This is the same process as #4, removing the Decimate line in the avisynth script and changing the output framerate to 29.970 for FFMPEG. This script shows all progressive frames and has audio sync in VirtualDub and the audio sync is correct in the final output file.

Guest
25th January 2007, 05:20
First, the presence or absence of Decimate() theoretically has no effect on audio sync.

Tell us more about the audio desync. Is it a constant offset or does it change during the course of the clip? Try to characterize this as well as possible for us because it affects the course we take next.

I'd also like you to try this with a DivX encode, as I am suspecting ffmpeg here. What happens if you leave the decimate in but omit the -r option on ffmpeg? Shouldn't it pick that up from the input file?

ScootyPuffJr
25th January 2007, 07:34
The audio always starts out in sync and then slowly goes out of sync. After about 40 minutes its a good 1-1.5 seconds out of sync. Everything I've encoded so far has had this problem. I definately believe it could be FFMPEG, as pretty much every solution I have tried uses it, but most people seem to have good results so I kept trying. I'm currenlty using build 4759 of ffmpeg. I've tried newer ones but they don't seem to recognize the avisynth input files.

I encoded a new mp4 without the framerate specified, and with the decimate(cycle=5) in the avs script. The resulting file was 19.18 FPS. EDIT ... oops, I both FF'd and IVTC'd, ... reencoding ...

I'm installing GKnot with the x264 and XVid codecs. I'll follow the guide and get the vob encoded to see what I get.

Thanks for the quick reply!!!!

Guest
25th January 2007, 18:17
Keep it simple, just use Force Film.

ScootyPuffJr
25th January 2007, 21:32
done ... DGIndex (1.4.8) ForceFilm -> AVS (2.5) -> FFMPEG (build 4759 cygwin) no framerate specified. The resulting file is about 2 seconds out of sync. I've tried it on 5 different PCs with the same software pack, 2 were fresh xp builds, the others are MCE 2005 builds, all pretty clean. The only non-standard windows encoders I have installed are the NVidia DVD Decoders installed on the MCE machines.

Here are the processing scripts. Any ideas?

d2v
----------------------------------------
Stream_Type=1
MPEG_Type=2
iDCT_Algorithm=3
YUVRGB_Scale=1
Luminance_Filter=0,0
Clipping=0,0,0,0
Aspect_Ratio=4:3
Picture_Size=720x480
Field_Operation=1
Frame_Rate=23976 (24000/1001)
Location=0,0,0,106577
FINISHED 99.91% FILM

AVS
----------------------------------------
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\dgdecode.dll")
video = mpeg2source("D:\Video\iPod\file.d2v")
audio = WavSource("D:\Video\iPod\file.wav")
AudioDub(video, audio)
BiCubicResize(336,252)
Crop(8,6,-8,-6)

FFMPEG
----------------------------------------
"D:\Video\iPod\Apps\ffmpeg\ffmpeg.exe" -i "D:\Video\iPod\file.avs" -y -bitexact -vcodec h264 -b 768 -bufsize 768 -coder 0 -vlevel 13 -g 250 -4mv -mbd 2 -trell -cmp 3 -subcmp 3 -mbcmp 3 -s 320x240 -qmin 20 -qmax 20 -f mp4 "D:\Video\iPod\file.mp4"

Guest
25th January 2007, 21:57
I asked for a DivX encode to rule out ffmpeg.

ScootyPuffJr
25th January 2007, 23:02
sorry, still working on that. I installed GKnot and tried installing the x264 coded, but couldn't get it working. I'll switch over to xvid instead. I've never used anything but DGIndex, AVISynth and FFMPEG so it's taking me a little while to figure things out :)

Guest
25th January 2007, 23:23
You don't need GKnot. Just load the AVS in VirtualDub, select the DivX or XviD codec, and get 'er done!

ScootyPuffJr
26th January 2007, 04:23
I didn't realize it was that easy!

I encoded the video with xvid and I don't seem to have the same audio sync problems. It appears to be out of sync once in a while, but I need to do more testing. It looks like I need to find myself some new codecs and a new iPod encoding method ... unless you think there is an easy fix for FFMPEG??

Blue_MiSfit
26th January 2007, 04:50
MeGUI has worked well for me - it has an iPod x264 / AAC profile. Write appropriate avisynth script, select it and appropriate audio file, select ipod profile, and encode.

ScootyPuffJr
26th January 2007, 05:05
I tried meGUI, and got horrible results with the audio encoding so I didn't go any further. I installed the latest version of megui, the Nero AAC encoder and followed the Ipod_Conversion_Guide on mewiki.The resulting file sounded like it was being played through a very long tube. If you have any tips to get better audio I'd be glad to give it another try ...

** EDITED **

I was playing the converted AAC file in quicktime and it sounded horrible. After muxing the audio sounded great and was in total sync with the video. Thanks for getting me to take another look at it :)

Guest
26th January 2007, 15:02
Scooty,

I just wanted to point out that MeGui uses DGIndex/DGDecode internally, so you could have succeeded with your low-level approach by encoding with x264.exe. But if MeGui is simpler for you, that's fine!

ScootyPuffJr
27th January 2007, 01:05
neuron2 ... that's what I actually plan to do. I'll be using the meGUI process (DGIndex/NDAAC/x264/MP4Box) and creating batch scripts around those individual tools so I can just drop a whole bunch of VOBs and leave. I convert full seasons/series at time, and there's just too much manual involvement with any GUI.

I love DGIndex and it's text-based d2v file ... it makes it nice and easy for me to VBScript a VOB -> MP4 process once I find the video processing settings I like. Keep up the great work!

Thanks for all the help guys. I should have abandoned FFMPEG earlier ... I think I just put so much time into it I coudln't bring my self to throw it away :)

ScootyPuffJr
29th January 2007, 21:29
Well, I've encoded about 20-30 things, and I'm still getting some audio sync problems with the older TV material (star trek TV shows). The audio fades in and out of sync just slightly. For the newer shows (BSG, Firefly) it seems to be dead on. Any ideas?

Also, I was wondering about x264 and the iPod. Everyone says to use the ABR setting in meGUI, but I can't find alot of info about it. I'm guessing this is a 1-pass profile, since all the file sizes come out the same. Is there a way to use 2-pass and keep the file in iPod spec? I tried it but x264 exceptioned out on me.

Thanks again!

Guest
29th January 2007, 22:03
Well, I've encoded about 20-30 things, and I'm still getting some audio sync problems with the older TV material (star trek TV shows). The audio fades in and out of sync just slightly. For the newer shows (BSG, Firefly) it seems to be dead on. Any ideas? How much is slightly? What is your DGIndex field operation? What is the film percentage as determined by DGIndex?

ScootyPuffJr
29th January 2007, 22:22
I'd say roughly a quarter of a second, maybe a half second ... just enough to be noticable, but not completely obvious.

DGIndex Film percentage is 99.91% FILM - I was force filming rather than IVTC. I just noticed that I'm also getting .d2v.bad files for each d2v file, both when honoring pulldowns and using force film.

Guest
30th January 2007, 00:37
DGIndex Film percentage is 99.91% FILM - I was force filming rather than IVTC. I just noticed that I'm also getting .d2v.bad files for each d2v file, both when honoring pulldowns and using force film. Try again with DGIndex 1.4.9 beta 13.

ScootyPuffJr
30th January 2007, 07:25
The second file had the same problem, so I started tracking back, and it looks like the source is the actual problem - the DVD itself appears to be badly mastered, and the audio sync goes in and out slightly ... sorry! ... no wonder they all got remastered last year :)

ScootyPuffJr
1st February 2007, 09:18
Thanks Dasiy, I'm actually trying to avoid using a conversion GUI and trying to learn the actual tools to really get a good understanding of, and more control over, the process.

neuron2, thanks for your help and patience. Also, thanks for writing a great tool, and some of the best documentation/video information I've found yet. I wish every tool that I have found and tried was documented so thoroughly! ... and you provide excellent support as well :)