PDA

View Full Version : Fixing progressive out of sync audio with VirtualDub script


vemon
24th September 2008, 22:14
I've managed to record a bunch of video clips using CamStudio + ffdshow (uncompressed video & pcm audio) which all have different length audio and video tracks (audio track is always shorter than video track). I'm not sure what's the source of the problem since uncompressed video shouldn't introduce any compressing overhead.

Anyways... I created a VirtualDub script to fix the problem but it still has some issues. I'm only able to calculate the desired time stretch ratio for the audio track by manually entering the video frame rate and the audio sampling rate. If these could be determined programmatically I would have a completely automatic script for fixing my video clips.

My question is: Does anyone know if it's possible to get the video frame rate and the audio sampling rate in a VirtualDub script?

At the moment my script looks like this:


declare infil;
declare stretchfil;
declare outfil;
declare ratio;
declare fps;
declare audiosrate;

fps = 25;
audiosrate = 44100;

VirtualDub.Open(VirtualDub.params[0],0,0);
VirtualDub.video.SetMode(0);

VirtualDub.audio.SetSource(1);
VirtualDub.audio.SetMode(1);

VirtualDub.audio.EnableFilterGraph(1);
VirtualDub.audio.filters.Clear();

infil = VirtualDub.audio.filters.Add("input");

stretchfil = VirtualDub.audio.filters.Add("time stretch");
ratio = (((double)VirtualDub.video.length / fps) - 1) / ((double)VirtualDub.audio.length / audiosrate);
VirtualDub.Log("calculated stretch ratio:");
VirtualDub.Log(Sylia.ToString(ratio));
VirtualDub.audio.filters.instance[stretchfil].SetDouble(0, ratio);
VirtualDub.audio.filters.Connect(infil, 0, stretchfil, 0);

outfil = VirtualDub.audio.filters.Add("output");
VirtualDub.audio.filters.Connect(stretchfil, 0, outfil, 0);

VirtualDub.SaveAVI(VirtualDub.params[1]);

setarip_old
25th September 2008, 00:50
Hi!

Looks like more work than may be necessary.

1) Set VirtualDub's "Video" to "Direct Stream Copy"

2) Set "Framerate" function (From "Video" dropdown menu) to "Change so video and audio durations match" and then,

3) Use VirtualDub's "Job control" function (From "File" dropdown menu) to select all of the files you want to process...

vemon
25th September 2008, 10:50
I also thought it was possible to just adjust the video framerate to achieve this but it seems to do nothing at all. That's why I created my script in the first place.

Although I think I used "Full processing mode" when adjusting the framerate. Could this prevent it from working?

[edit]
Just tested with "Direct Stream Copy" and still no effect when adjusting the source framerate.