My Departement Of Nerdcore Enthusiasm

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

Viser opslag med etiketten CLI. Vis alle opslag
Viser opslag med etiketten CLI. Vis alle opslag

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)




mandag den 17. oktober 2011

Create scrolling move text from a pdf file

If you look around on this blog you can see that much of it is about being able to produce video effect without a fancy graphic video editing program. I find it fuzzy to work with these heavy video editing programs when I often sit and just have a small computer at my disposal. My scripts can produce a good result without me having to sit and pull elements in place with the mouse drag-and-drop in a graphics program. I can instead give a precise command from a commando line and then just wait to see the job gets done. This script can be slow to get through the process. The example of “rolling credits” shown here took about half an hour to process on my little ASUS eee pc. But in that time I am free to work on something else. That works fine for me.

This script creates scrolling text video clip like the rolling credits of a movie. It makes it out of a PDF or PS (PostScript) document. That is when you want to produce your rolling credits, you simply typing them into a word processing program like OpenOffice Writer or AbiWord, etc. and then save (save a copy or export) as a pdf (almost any modern word processor will do this). You should set the page size to A4 paper size. Top and bottom margin should be an inch with is equal to 2.54 cm. The spread of your document equals to the screen stretched so the distance you have between the text and the edges of the document corresponds to what you're going to see on the screen.  I have usede a Font Size of 20 points which I think is a good starting point but it is up to you. You can format text just like you would in your word processing system. Use black for the text and white for the background. Although the text is spread out over several pages in the word processing program try to imagine that it's just one long continuous text when you set it up. The resulting video clip is white text on black background. This concept can obviously be expanded so that the text will run over the "living pictures" in your video, but it leads too far now. The script is also currently limited to producing a video output in VGA format 640 x 480 pixels.

For this script to work you must have the following programs on your computer:

1. The scripted is a bash shell script so you must have a bash shell environment that you have on most Unix platforms. OS X, Linux (Ubuntu, Red Hat, puppy etc), Solaris, etc.

2. The basic program package Netpbm command-line based and script-based image processing.

3. Ghostscript (GS), the classic Gnu / open-source tool for PDF and PostScript handeling.

4. Ffmpeg a really nice strong basic commando line based film/video editing and conversion tool.

To run the script you must have opened a terminal window. Xterm Aterm.. whatever. Then, in your working directory you should have your PostScript file and the script. You give PDF or PostScript file as an argument to the script like this:

./rolling yourfile.pdf

and now it will take a while to produces a video clicp script with "rolling credits" out of your document.

The script is here. If you want to download it you can right-click and then choose save target as, or similar. Now make sure the script is executable. You can probably also do the right-click action or from a commando line with

chmod +x rolling

http://www.mimoart.ooz.dk/rolling

If for some reason would want to see the pdf file I've used as the basis for this video eksepel so it is here.

http://www.mimoart.ooz.dk/youare.pdf