VirtualDub script for deshaker (NOT Vegas!)

RichMacDonald schrieb am 26.02.2005 um 07:16 Uhr
For those who use deshaker in VirtualDub, after much trial and error, I have a script that performs the task in one go. The following script:

1) Opens a clip "clip1" and runs pass 1 of deshaker.
2) Appends a 30 frame clip.
3) Runs pass 2 of deshaker and renders uncompressed to a temp file
4) Opens the temp file and trims the first 30 frames, saving to "clip-deshake".

The resultant clip is the same length and position as the original. It may be added as a take back into vegas or whatever you want to with it.

Note: I've hard-coded the names of the files, including the log file. Obviously you'll need to change these. I am not processing the audio.
Also, those of you who prefer different codec and deshaker settings need to customize it.
See the discussion following.

----------------------------------------------------
// "deshaker pass1"
VirtualDub.Close(); //cleanup from whatever was going on before
// paste point 1A, see comments at end
VirtualDub.audio.SetSource(0);
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetInputFormat(7);
VirtualDub.video.SetOutputFormat(7);
VirtualDub.video.SetMode(3);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetIVTC(0,0,-1,0);
VirtualDub.video.SetCompression(0x75796668,0,10000,0);
VirtualDub.video.filters.Clear();
VirtualDub.video.filters.Add("Deshaker v1.6");
VirtualDub.video.filters.instance[0].Config("4|1|30|4|0.911392|2|0.911392|2|720|480|1|1|1|5000|5000|0|0|4|1|0|2|5|40|300|4|C:\\temp rendering\\vegas deshake\\DeshakerScript.log|0|0|0|0|0|0|0|0|0|0|0|1|0|1|99|99|99|99|1|1|30|30|0");
VirtualDub.audio.filters.Clear();
// paste point 1B, see comments at end
VirtualDub.subset.Delete(); //removes any selections. Just belt and suspenders
VirtualDub.Open("C:/temp rendering/vegas deshake/clip.avi",0, 0);
VirtualDub.Preview(); //runs pass 1

// "deshaker pass2"
VirtualDub.Close();
// paste point 2A, see comments at end
VirtualDub.audio.SetSource(0);
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetInputFormat(7);
VirtualDub.video.SetOutputFormat(7);
VirtualDub.video.SetMode(3);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetCompression(); //uncompressed intermediate. Have disk space available
VirtualDub.video.filters.Clear();
VirtualDub.video.filters.Add("Deshaker v1.6");
VirtualDub.video.filters.instance[0].Config("4|2|30|4|0.911392|2|0.911392|2|720|480|1|1|1|5000|5000|0|0|4|1|0|2|5|40|300|4|C:\\temp rendering\\vegas deshake\\DeshakerScript.log|0|0|0|0|0|0|0|0|0|0|0|1|0|1|99|99|99|99|1|1|30|30|0");
VirtualDub.audio.filters.Clear();
// paste point 2B, see comments at end

VirtualDub.Open("C:/temp rendering/vegas deshake/clip.avi",0, 0);
VirtualDub.Append("C:/temp rendering/vegas deshake/30frame-noaudio.avi");
//dummy 30frame clip that must have same audio as original clip (i.e., with or without audio)
VirtualDub.SaveAVI("C:/temp rendering/vegas deshake/temp.avi"); //temp file. Is NOT deleted

//Trim first 30 frames off result. Use final compression settings
VirtualDub.Close();
// paste point 3A, see comments at end
VirtualDub.audio.SetSource(0);
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetInputFormat(7);
VirtualDub.video.SetOutputFormat(7);
VirtualDub.video.SetMode(3);
VirtualDub.video.SetFrameRate(0,1);
// paste point 3B, see comments at end
VirtualDub.video.filters.Clear();

VirtualDub.Open("C:/temp rendering/vegas deshake/temp.avi",0, 0);
VirtualDub.video.SetCompression(0x75796668,0,10000,0); // I chose Huffyyuv. YMMV
VirtualDub.video.SetRange(1001, 0); //trim 1st 30 frames. Argiments are millisecond offsets from start and end. Manual is wrong
VirtualDub.SaveAVI("C:/temp rendering/vegas deshake/clip-deshake.avi");
VirtualDub.Close();
----------------------------------------------
Most of the script is simple stuff auto-generated from VirtualDub. To check or alter the values, load VirtualDub, set the video and audio as you need it, load deshaker and configure it, set it as pass 1 and save it. Now File->Save Processing Settings to store all this to a text file. Then copy that text and paste it in between "paste point 1A" and "paste point 1B". Go back to deshaker and select pass 2. Now repeat File->Save Processing Settings, copy that text and paste it inbetween "paste point 2A" and "paste point 2B". For the final rendering, set it up as needed and paste into 3A and 3B.

Note that I chose to store the intermediate file as uncompressed then I used Huffyuv as the final. Can't say I recommend any of the standard codecs.

Note that you'll want to delete the temp.avi clip when you're done.

As for the 30frame dummy clip, simply create a 30 frame clip in vegas using the media generators and render to avi. If your clip1 has audio, you'll need audio in the dummy clip. If your clip1 doesn't have audio, then you'll need a dummy clip without audio. Early on I also had problems getting VirtualDub to append/merge two clips with different codecs but that issue hasn't been a problem recently. I was probably doing something wrong beforehand.

This was actually quite a difficult job. Many thngs went wrong until I got it right and I wouldn't be surprised if its still very touchy. If VirtualDub has a problem with the script, step it manually in VirtualDub and see if you still have the error.