Wednesday, October 19, 2011

Video stabilization on Ubuntu Linux!

Video taken by handheld cameras is generally shaky. To some extent, this video can be deshaked by video stabilization. There are many commercial software available for video stabilization. Fortunately, Ubuntu Linux comes with an application called "transcode" that can be used to stabilize videos. If this application is not installed, you can run the following command to install this:

  sudo apt-get install transcode


Video stabilization is two step process. The first step analyzes the whole video clip to extract camera motion information, and the second stabilizes the video according to the detected camera motion (stored ar *.trf in the same folder after first step).


  • For the first step, you have to go to you the directory where you have stored your videos and execute the following command:     
          transcode -J stabilize -i yourvideo.MP4 

when you execute this command, you will probably get the following error "transcode [filter_stabilize.so] warning: unsupported Codec: 2 (11| 0| 9)" (unless this bug is already fixed in your version of transcode). Some websites suggested including mplayer in command "transcode -J stabilize --mplayer_probe -i yourvideo.MP4", but it doesn't seem to work.  

A working solution to this problem is found at [1] as following:
    • Visit the vid.stab download page and download the latest plug in binary. Currently called "Version 0.75, binary files (linux 32bit i586), works with 1.1.X". This is a packed .tgz file that contains the plug in (filter_stabilize.so andfilter_transform.so).
    • Unpack the plug in: you can double click the .tgz file, double click the stabilize folder,  then drag the two .so files to the Desktop.
    • Open a terminal and move filter_stabilize.so and filter_transform.so from the desktop into /usr/lib/transcode/ overwriting the files with the same names. Type something like: sudo mv /home/YOURUSER/Desktop/filter_* /usr/lib/transcode/ (where YOURUSER is your Linux user name).
    • Execute the command again:
                 transcode -J stabilize -i yourvideo.MP4 
  • For the second step, execute the following command:
      transcode -J transform -i yourvideo.MP4 -y xvid -o yourstabilizedmovie.avi

The resulting deshaked video is stored in the same directory as yourstabilizedmovie.avi.

Enjoy!!!
 

References