My Departement Of Nerdcore Enthusiasm

Tutorials and the like. Things which I have committed myself to. Often linux/UNIX-related.

tirsdag den 17. december 2013

The counter rotating script for video editing


A demo of a small set of scripts I've made for counter rotating a video clip. I call it

The counter rotating script for video editing

The script is help full if you have a video recording where the camera have been rotated back and forth while recording and you want to stabilize it or counter rotated it either clockwise or counter clockwise back to an almost stable, realistic view-orientation.

Background for the scripts
On the fourth of October 2013 in the city of Aarhus (in Denmark) a good friend of mine took a very hand-held recording of my 20 minutes long solo performance "Stoned" while I performed it live. The pictures were very beautiful, but the camera rotates during filming. If the beautiful recording should be used for something I had to find a way to contra-rotate it so you could watch the video in a fairly horizontal orientation all the way through. It was not only about rotating the video recording from eg landscape to portrait format. That would have been an easy task, but here the rotation had to happen along the way so it hat to be continuously counter-rotated. When I was doing "Dance of a Newsboy" an earlier peace (2012), I spent an incredibly long time to make an a homemade method to zoom in a video sequence which had already been recorded. A reasonably advanced interactive shell script that I think is the coolest piece of programming I have so fare made. As soon as I got my recording of "Stoned" home in October I started "coding". I would expand the old script so it could both rotate and crop the video sequence. Before the process starts I was writing all the "frames" of the video clip out as images. There is a 20-minutes of video recording and there are 24 frames per second. Overall it gets to over 30.000 images. All of these images are now added extra padding at the top and bottom so they are 100 percent square (1280 x 1280 pixels). It provides a good starting point to rotate them. I started to make these scripts back in October and now I'm done with the coding and have started to rotate and crop the thousands of images.

How it all works
The script treat 96 images at a time which corresponds to 4 seconds . The five pictures illustrate the process . What is is not visible from these still images is the dynamic flow from image to image embedded in the script, but the pictures illustrate fairly the steps it goes through. This process can perhaps be compered to steering through a video recording with a flight simulator, if that makes any sense :-). I hope that I can "manage" my way through all 30,500 pictures/frames before December 1 where I will start on an new education.

The original image is "lying down". It is in the format 720p (1280 × 720 pixels)


Here the picture is made ​​squareA "compass" is put upon the imageAn angle value can then be entered for rotation of the image. Don't worry you do not rotate each and every image separately. The script process 96 images in one operation corresponding to 4 seconds of video.





Now the image is upright.



The next phase is cropping. This is governed by a coordinate system consisting of a lot of small numbers in the image. There is a frame that can be placed in the image by entering the coordinates of the frame's upper left corner. This is not either done for each image separate, but for 96 images at a time. It has a starting value and other value to where the frame should end after the 96 images and then the cropping wanders gradually from one position to the other over the 96 images in one operation.

The finished cropped image is slightly smaller than the originalThe format is called WSVGA and is 1024x600 pixels.

A video that demonstrate how it is to work with this script.
If you want to skip the introduction stuff jump to time: 6.27 (on the video timeline)




Ingen kommentarer:

Send en kommentar