Blog
Stabilizing GH3 Video For Sony Vegas
Date: 19/5/2015
Tags: video
I have a GH3 camera that takes pretty nice video. Because I cheaped out and got a non-Panasonic prime for the lens, I don't have in lens stabilization. What I do have is a bunch of footage that needs stabilization so I've been looking around for software based solutions.

The first (free) one I heard about was Blender and it's point tracking. After downloading that and playing around with it I found it very limited in what footage it can work with. As soon as you pan or zoom it becomes very difficult to keep the footage zooming and panned correctly. There are scripts to help but because it's not core functionality it just gets complicated fast.

Then I heard about Deshaker, which primarily runs as a plugin for VirtualDub. A tool which I haven't used in a very long time. So I downloaded both of those and got to work testing it on my footage. Immediately it was obvious that it was vastly better and more powerful that Blender.

The first issue I faced when using VirtualDub was that the input video was .MOV files off the camera. This is the format from ffmpeg:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bec+tanner 038.MOV':
  Duration: 00:09:03.36, start: 0.000000, bitrate: 49552 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 48004 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Stream #0:1(und): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
    Stream #0:2(und): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
And VirtualDub uses .AVI files. Next step is converting the video to an AVI without re-encoding it. And that is best accomplished by my old friend ffmpeg. Which has the ability to convert between compatible containers without loss of quality and time caused by re-encoding the video. My initial attempt failed because the AVI container doesn't support big endian audio (the default off the camera). So I converted that to little endian using this command:
ffmpeg -i "input.mov" -vcodec copy -codec:a pcm_s16le "output.avi"
Now I could load my files into VirtualDub and stabilize them. The process basically involved adding 2 instances of the Deshaker plugin to the filter pipeline. The first one is set to "pass 1" and enabled. Disable the 2nd instance. Then go to the start of the video and runing the Output Playback mode. This generates all the motion vectors. Disable the first pass instance of Deshaker and enable the 2nd pass instance. Now you can export the video using your desired compression. I don't like any of the built in compressors so I downloaded the x264 codec and used that.

But the output had a problem. When the camera panned to track people walking, they appeared to jump back and forth in the stabilized output. Very odd looking. So I went frame by frame and noticed that in the source video each pair of frames coming through was the same. Deshaker then would get confused by this and shift the intermediate copy of the frame by more than the new frame. I thought the best way to get around this was to delete these redundant frames from the GH3. Fortunately VirtualDub comes with just such a filter: interpolate

By putting it in front of the Deshaker instances I got nice clean output, free of stuttering. At least as far as it would play in VLC. However when I loaded that into Sony Vegas there was big problems playing the AVI files back. Basically it would drop to a slide show, and on top of that there was corruption in the rendered output. Mulling my options I started looking for a way of getting the video out of VirtualDub without using the AVI container format. Fortunately there is a way. By installing an external encoder, which in my case was more just redirecting output to ffmpeg.

I found that by adding the right external encoder you can call ffmpeg to encoder the video straight from VirtualDub. The process involves writing out a "ffmpeg-1.vdprof" text file with the content from that link. Then importing that into VirtualDub and editing the details a bit. I decided to lower the -crf parameter to 16 to make it pretty much visually lossless. I don't want the stabilization to drop the quality at all.

Now I can bring that footage into Vegas and it plays smooth as butter. But it might have sent a few hairs grey.
Comments:
134444455555
17/08/2015 12:46pm
How to Escape Doing Homework!
 
Reply
From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]