Mass Deshaker script v1.0
------------------------------
Download it from here:
mass_deshaker1.0.zip
PROBLEM:
HD camcorders became widespread recently. However, as probably all owners of these cameras have already realized, viewing HD footage shot without a tripod is at least tiresome or dizzying in the extreme because of the shaking. The increased detail magnifies the negative effect of tremors in hand shake, camera movement and zoom.
Until manufacturers improve their hardware stabilization up to a point where shaking is not an issue anymore (which I hardly believe anytime will come) post-processing the footage may help. Recently I reviewed available deshaking software solutions I could find, plugins to NLEs, standalone tools, and I found that far best is Gunnar Thalin's free (but not open source) Deshaker plugin to VirtualDub. Check what it is capable of on youtube.
The problem with Deshaker that it is quite hard to use. One need to setup VirtualDub for its two phases for each clip, the parameters are not trivial, and it also introduces an audio shift when using future frames for filling up the missing borders. It is beyond the reach of people who can use their favourite NLE, but do not have experience with VirtualDub and advanced video editing, and it is definitely hard to mass-deshake a series of footage with it.
SOLUTION:
I wrote a simple shell script which I use to mass-deshake HD video footage with Deshaker for further video processing in an NLE. Installation is a bit complicated, but after that it is just moving files into directories and clicking on deshake.bat. Practically I filter all my HD shots through it. As I want to edit the clips later, the output is generated with the Lagarith lossless codec to minimize recompression artifacts. I found Lagarith to be the best for this purpose (and it is also free to use).
WHAT DO YOU NEED?
Thats the bad news: you will need lots of things for it to work.
1. First of all, patience and a computer which is powerful enough. Deshaking an average footage of 5-10GB can take 1-3 days to finish in my i7 920 2.66GHz. I prefer running through nights, but VirtualDub runs with low priority, one core and minimized, so it is fine to do other things while deshaking runs in the background.
2. Plenty of HDD space. Lagarith is a lossless codec and the output can be huge in size. As a rule of thumb my 13Mbps Panasonic AVCHD videos will grow to 20x the size, so you need about 200-300GB of free space for the above mentioned "average" shot. Playing back these clips smoothly is hard because of their size, so I recommend using an NLE which can use proxy files (like VideoStudio or Vegas with the ProxyStream script).
3. Input format: the script uses avisynth's DirectShowSource() function to import the source material, so you should check that you are able to play your clips through DirectShow. In general, if you are able to play the clip in Windows Media Player you should be able to process it. Containers or file extensions do not matter, it works with .mts, .m2ts, .avi, .mpg or whatever mix you have.
4. You need to install:
a/ VirtualDub: http://www.virtualdub.org/
I am using 1.8.8 build 30091. Should work with other versions, too.
b/ cygwin: http://www.cygwin.com/
I used unix shell scripting as my windows scripting knowledge is even more inferior to the unix one. During setup find the package called 'bc', its in the 'Math' subsection and install it. You should have bash, sed and bc at least. Cygwin's bin/ directory must be in the system PATH variable.
c/ avisynth: http://avisynth.org/mediawiki/Main_Page
2.5.8 is tested.
d/ Gunnar's SmoothDeinterlace plugin, ported by Xesdeeni for avisynth: http://www.guthspot.se/video/AVSPorts/SmoothDeinterlacer/
I use it for deinterlacing if necessary. Copy SmoothDeinterlacer.dll into AviSynth's plugin directory (Program Files\AviSynth 2.5\plugins).
e/ Lagarith lossless codec: http://lags.leetcode.net/codec.html
f/ and of course Deshaker: http://www.guthspot.se/video/deshaker.htm
Tested with 2.4. Copy deshaker.vdf into VirtualDub's plugin directory.
HOW TO USE?
If you have everything installed, extract the .zip from above to a directory of your choice, put some clips into the directories in the source/ subdirectory, and run deshake.bat. The script starts in a command window and prints the name of the actual clip as it processes them. It runs VirtualDub 3 times for each clip. VirtualDub.exe is assumed to be in the C:\Program Files\VirtualDub or C:\Program Files (x86)\VirtualDub directory. If it is not there, specify its location in the deshake.bat file (see script parameters below). Result clips appear in the clips/ directory, while finished clips are moved into the finished/ directory.
WHAT DOES IT DO?
The script works on the files put in the source/* directories. Each file is deshaked with a Deshaker setting depending on the directory. The results are generated in the clips/ directory in .avi, and finished clips are moved into the finished/ directory. You can interrupt the script anytime and restart it to finish the processing later, it will continue from where it was stopped. Clips are processed in 3 phases: the first two run Deshaker on the (optionally de-interlaced) clips, and the audio is delayed to match the video according to the fps of the shot. The third pass removes the first 30 frames added by Deshaker, and optionally rescales the video and trims the beginning and the end if necessary (I added this due to a Sony camcorder for which some reason playback missed 1 sec of audio from the end of each clip).
Script parameters (all are optional):
deshake.sh -p -x integer -y integer -d directory -b integer -e integer
-p: do not perform de-interlacing (for example you are having progressive material like 1080p/24).
-x, -y: output x and y size of the video (integers, default is 1920, 1080). Output is resized and the aspect ratio is changed.
-d: directory of VirtualDub.exe in cygwin format (/cygdrive/drive_letter/dir, use \ to escape whitespaces). Default is /cygdrive/c/Program Files/VirtualDub or /cygdrive/c/Program Files (x86)/VirtualDub.
-b, -e: additional msecs to trim from the beginning and the end of each clip (default is 0, 0).
You can edit these options in deshaker.bat. You can also create a shortcut to the batch file.
DESHAKER SETTINGS AND GUIDE:
There are 4 basic settings:
1. no_deshake: it simply converts the clips to the overall output format (using the size, trimming and deinterlacing parameters with Lagarith). It is included to simplify the workflow if you wish to work on the same format for all clips later.
2. blend: Large borders, "soft borders" option turned on. *RECOMMENDATION: I use it if there is movement in the edge of the take.
3. sharp: Large borders, "soft borders" option turned off. *RECOMMENDATION: I use it if the edge of the shot is static, that is, there is no movement which crosses the edge.
4. zoom: Zoom in to remove borders. *RECOMMENDATION: I use it if the subject is well constrained to the middle of the shot, like a bird walking in the grass, and the shot is not hurt by cropping the edge.
All of these (except the no_deshake) come in two flavors: "weak" and "strong".
- *RECOMMENDATION: I use "weak" if the camera is moving in the scene (e.g. panning), and the background is not steady.
- *RECOMMENDATION: I use "strong" when I judge that the background should be absolutely steady.
Probably even the weak setting will be too strong for many people, but thats how I like it. It is also a matter of taste, but I prefer having blended edges to a change in the composition by zooming in and loosing information in the screen edge, so 80% of my shots go into the blend_weak folder. But it is up to you. You can change the parameters in the .vcf files.
CREDITS, LEGAL AND DISCLAIMER:
You are free to modify this script whatever way you like, but if you distribute it please mention me.
Thanks to Gunnar Thalin for the amazing deshaker and the de-interlace plugin.
The script is provided as is, no guarantees. It is moving around files, it is deleting files, so it can be potentially harmful, although I had no problems so far. So use it carefully and keep copies of your source somewhere else.
I am not a unix script expert, so it is probably lame in many places. You can send improvements or comments to the PM here or to the mail address in the README.txt. Thanks!
+ Reply to Thread
Results 1 to 25 of 25
-
-
Great stuff, thanks for creating this and putting such a comprehensive post up. I'll definitely look into this when I need to do mass deshaking.
-
Sounds interesting, but I'll stick to my simple version thanks
http://forums.virtualdub.org/index.php?act=ST&f=5&t=17772&p=74325&st=28&hl= -
Hello,
I did exactly what you advised and I ended up with the following error:
./deshake.sh: line 170: bc: command not found
Avi file is not finished and can be found in temp folder while it should go to finished/ directory.
Any idea what is wrong? -
I used Gunnar's Deshaker...It's pretty good when you figure out the settings.
However, using deshakers is like a doctor mindlessly writing prescriptions rather than telling you how to prevent illness in the first place.
I remember reading up on HD technique years ago...The first thing it mentioned is how important it was to use a tripod. Fortunately, this was already second nature to me yet still an inconvenient truth to rank amateurs. When it comes to shooting, it's like separating the men from the boys. I find myself carrying a 50 pound tripod with a little 1 pound camera attached.
What you may want to do is simplify rather than complicate. -
I agree that if you set out to film something then it's really showing a lack of commitment to not use a tripod.
But, sometimes we just don't want to carry a tripod. Not all filming sorties are pre planned. Sometimes we just take a camera just in case, and make do with whatever support is available.
Sometimes we have footage that is perfectly usable once deshaken.... so why not? -
Sorry, it looks like bc was not in cygwin's default, I added it later. I have modified the text of the initial post.
You should run the cygwin install again (it is not necessary to remove anything), and find the package called 'bc: the GNU numeric processing language and reverse polish calculator' in the list under the 'Math' section and click on it until you see 'Install', then continue with the installation. Also make sure that you have the "Unix/binary" set as the default text file type.
Originally Posted by mrowkapj -
If you believe carrying around a 50 pound tripod is simplifying, then let me stay the pitiful amateur I am...
Home video is not low-cost movie making. It never was.
Btw tripods are for sissies. The really dedicated guys lay tracks for the camera dolly. :P -
Originally Posted by takbal
-
Ok, I download I think everything.
Where should everything (files, installation) be ?
I do not understand b part especially
b/ cygwin: http://www.cygwin.com/
You should have bash, sed and bc at least. Cygwin's bin/ directory must be in the system PATH variable.
Where should all the files be after downloaded ? Should let it install by itself ?
How to use it in virtual dub ???
Thanks -
3. Input format: the script uses avisynth's DirectShowSource() function to import the source material, so you should check that you are able to play your clips through DirectShow. In general, if you are able to play the clip in Windows Media Player you should be able to process it. Containers or file extensions do not matter, it works with .mts, .m2ts, .avi, .mpg or whatever mix you have.
quote]
I seem to have issues with playing the Windows Mdeia Player ... not sure why .. used to be able to play it no issues ... now I cannot, I might try reinstall perhaps ???
Any workarounds ?
Thanks -
Originally Posted by MJ Peg
in Vista 32 bit where to find please /
C:\Data\Progs\Deshake
Could you upload the zipped file needed ?
How do you get such smooth edges ??
Thanks -
Originally Posted by holeepassion
Originally Posted by holeepassion
@bash -e ./deshake.sh
into
@bash -e ./deshake.sh -d /cygdrive/*drive_letter*/*directory*
use \ before spaces if you have any in the directory path. -
Camera's with stabilization do exist.
I've seen it in a big warehouse for consumer elektronics and it looked good.The flag once raised will never fall! -
The script will start VirtualDub on its own, until you put it into the C:\Program Files\VirtualDub directory. Otherwise, you have to define its location as a parameter passed to the script. To do this, edit the deshaker.bat file, and change
@bash -e ./deshake.sh
into
@bash -e ./deshake.sh -d /cygdrive/*drive_letter*/*directory*
use \ before spaces if you have any in the directory path.[/quote]
ok i got this comment saying bash is not recognised as internal or external command. Must be something to do with this explanation but sorry cannto really work it out
i copied the virtualdub into c:\program files\virtualdub ....
so, how should i edit ? i cannot understand the last two statements ????, should i copy everything and change driveletter and directory name ?
did not work still ... hmmmm
sorry for the trouble and thanks ....
not so tech in computer programming ... -
b/ cygwin: http://www.cygwin.com/
You should have bash, sed and bc at least. Cygwin's bin/ directory must be in the system PATH variable.
please explain this step ? ... especially the path variable .. when i install, what do i exactly need to do ?
thanks -
Originally Posted by holeepassion
Either create that structure or edit the scripts to point to somewhere else.
Originally Posted by holeepassion
Good luck 8) -
Hi, how to change a compression codec not to have so hudge files. My hard drive is too small to handle this.
With regards -
Hey takbal,
Excellent script, just what i was looking for; was getting fed up setting up each clip by hand.
However, I ran into a few issues. my data drive is HSF+ formatted, and for some reason I cannot drop the script there and run it, as file perms seem to be screwed in cygwin. Unless there is a way to tell cygwin to execute the file on that drive, I need the concept of binaries location (C: ) and data location for media and tmp files (F: in my case).
I did a bit of *sh scripting in my past life, so I had a go at modifying the script itself for this, but the $avsfile creation uses the code template files, which have $PATH as a variable, but which not declared in the main script, or anywhere I can see. Is this an internal deshaker/virtualdub variable? How can I change it to resolve to f:\<data_location>\tmp\deshaker.log for example? I put up with it for my little test, but I have a number of drives where I would want to run this against without changing it (or the subsequent passes files) each time.
My other request is, the zoom settings seem to have a 'zoom boing' effect going on. How to modify the settings file to do all the clever things you specified (amazing by the way for mts files) to either have a fixed zoom or no zoom at all (I can tweak that manually in premiere, to keep the best amount of visibility and natural flow. I had a look but it was all ones and zeroes for the deshaker settings...couldn't quite work it out..
My footage is very fast moving snowboard chase footage (ie I am holding a handheld camera while following a snowboarder at high speed) so the camera can be moving quite erratically sometimes, then is ok for a bit, etc. I need to apply just enough stabilisation for the audience not to throw up (it is quite queasy to watch), but not so much that deshaker is going nuts trying to make sense of it).
cheers
Colin
ps. I found the cygpath command quite handy in substituting some of your sed, eg:
WINSOURCE="$(cygpath -w "$SOURCE")"; -
Go to Control Panel - System - Advanced - Environment Variables, click "Path" in System Variables, and add the path of the Cygwin bin folder, separated from the rest of the entry by a semicolon. Example: if your original Path was like
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem
And you installed cygwin to C:\cygwin, the entry should look like
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;c:\cygwin\bin -
If you want to add compression to the output, modifying the related file called pass3.vcf should be easy. Load any clip in VirtualDub, and setup a compression you wish to use, then save the setup into a .vcf file from the File menu's "Save processing settings" option. Then replace the
VirtualDub.video.SetCompression(0x7367616c,0,10000 ,0);
line of pass3.vcf with the SetCompression line of the saved .vcf in a text editor. -
Hi,
As far as I know cygwin fills $PATH up from the windows environment (the one which is set up in the Control Panel - System - Advanced tab), but the "$PATH" string in the .vcf templates is just for sed to mark an insertion point of the full path of the template directory. Probably a bit misleading so unfortunate choice. You can replace it with "###WHATEVER###" or anything you like. For example, the line
cat $UNIXPATH/code/pass1.vcf | sed s/\$PATH/${EXT_DOSPATH2}/g >> $vcfname
simply replaces this string with the content of the ${EXT_DOSPATH2} variable.
To modify the Deshaker settings just set it up (phase 2) in VirtualDub in a way you like on an arbitrary clip. Then save the settings from VirtualDub as a .vcf file (File/Save processing settings), and replace the line containing "VirtualDub.video.filters.instance[0].Config" in the appropriate pass2_*.vcf with the same line of the saved .vcf file. -
Hey, thanks for this awesome script!
Sadly, I haven't been able to use it yet... I've installed all the required applications, but when I run the bat file, it says "please start this script from its own directory." When looking at the sh file, I see where this message originates, but have no idea what the code means. Please help!
if [ ! -x "pass1.vcf" -o ! -d "../tmp" ]
then
echo "Please start this script from its own directory."
exit
fi
-Nathan -
Here is a simple batch deshaker *.bat script I came up with while trying to batch encode some avis using ffmpeg. Tried it using deshaker and it works great:
for %%a in ("*.avi") do echo directshowSource("%%~fa") > "%%~na.avs"
for %%a in ("*.avs") do "I:\DESHAKER\virtualdub\vdub.exe" /s I:\DESHAKER\virtualdub\deshake11.vcf /p "%%a" "%%~na.deshaken.avi" /r /c /x && "I:\DESHAKER\virtualdub\vdub.exe" /s I:\DESHAKER\virtualdub\deshake22.vcf /p "%%a" "%%~na.deshaken.avi" /r /c /x
del *.avs
You can change the ("*.avi") to whatever file format you have to be deshaken. (as long as it can be imported as a directshowsource)
You have to change the directory to your own VDUB folder (as well as your deshake.vcf files)
"deshake11" and "deshake22" are pass 1 and 2 processing settings.
COPY all the files into the folder with your *.bat file.
Double click the bat file and all files will be deshaken.
Voila!!!!
I tried MJ Peg's script a long time ago and it works great, but very tricky to get it up and running. I eventually wrote the script even further to repair the 2 second audio delay afterward, and then cut the 2 seconds off the clip. THAT was very tricky, and ended up hanging all the time, so I stopped using it. Also a new deshaker version came out that fixed the audio delay.Last edited by zzyzx2; 26th Feb 2012 at 21:21. Reason: extra info.
Similar Threads
-
Script to mass convert VOB's to MPG's from the command line
By casperinmd in forum SVCD2DVD & VOB2MPGReplies: 13Last Post: 3rd Jan 2013, 16:08 -
How to Remove Camera Shake from iPhone 4S Videos (Batch Deshaker Script)
By preshing in forum EditingReplies: 1Last Post: 17th Apr 2012, 22:35 -
DeShaker how to?
By Asesinato in forum RestorationReplies: 20Last Post: 11th Apr 2012, 19:55 -
Deshaker help
By splitboarder in forum RestorationReplies: 13Last Post: 28th Apr 2011, 11:45 -
To Script or Not To Script, that is the Question... (Custom Videos)
By TheMcD in forum EditingReplies: 2Last Post: 21st Oct 2010, 10:11