How I play with videos

Intro

I sometimes play with videos. For that, I use G’mic.

Export images

G’mic is able to load directly videos, but my computer seldom has enough memory. So, before playing with video images, I create a directory called original and export every images of that video using MPlayer:
mkdir original
cd original
mplayer ../video.avi -nosound -vo png

It gives me tons of files. I could export as jpeg if I want those files to take less space, but I usually prefer the lossless png format.

Macro

Then I make a macro file that I always call macro.gmic. It contains the custom commands that I will need for my image processing. I make a very simple shell script which loops over every file, one at a time and output the result in another directory. This script looks like that:
#/bin/bash
mkdir -p processed
cd original
for i in *.png
do
gmic macro.gmic $i -my_command -o ../processed/$i
done

Play video without video

Once enough files have been processed, I use MPlayer to play those files as if they were a video to get a quick feeling of what it will look like at the end :
mplayer mf://*.png
I love that MPlayer feature.

One step, one directory

If my processing can be divided in different steps, I don’t hesitate to fill intermediate folders with half processed images. This way, I am able to tune separately each processing stage, it saves me time. Of course, it always finishes with a dozen of folders, a dozen a macros that have modified so many times that I don’t remember what version of which one is related to what folder and many thousands of files. Well, it is my hobby contained inside my computer, the mess is allowed.

Make a real video

At the end, to make the video from all that files, there are dozens of solutions. But experience has lead me to do first an mjpeg file with mencoder:
mencoder mf://*.png -o my_video.avi -ovc lavc -lavcopts vcodec=mjpeg
If I want to add some sound:
mencoder mf://*.png -o my_video.avi -ovc lavc -lavcopts vcodec=mjpeg -audiofile music.mp3 -oac copy
I finally reopen that my_video.avi in Avidemux to reencode it in H264.

Sound

If I have to play with sound, I use the command line tool SoX or Audacity if I want a graphical user interface.

Parallelization

The shell allows parallelization using the insanely complex command xargs. Parallelization is great, it can put all the cores and your had drive at 100% use, but it changes a bit the way things should be done, you need to have script file whose argument are passed by xargs.
For example, your script file script.sh will contain a single line :
gmic macro.gmic $@ -my_command -o ../processed/$@
and your script will be called by the command:
ls *png|xargs -I{} -P 4 ./script.sh {}
You can replace the 4 by any number, don’t hesitate to exceed the number of cores you have.

I say ‘you’ because personally, I don’t really use that trick, It puts my computer on the knees and prevents me from properly using it for something else in parallel.

Advertisements

3 thoughts on “How I play with videos

  1. Thanks for creating this article. A year ago I was trying to do something like this, but I only got as far as finding a way of splitting the video into images. I’ll have to try this out again. Have you ever used GIMP to process each of the images instead of G’MIC?

    • the “Gimp Animation Package” GIMP-GAP works this way and has a suite of scripts to help animation and frame-by-frame processing .. working interactively would be much slower than Zonderr’s batch based method. There are limited filtering techniques in VirtualDUB on Windows and AVISynth has a wide spectrum of plugins and can be scripted but again is Windows only. Maybe this is interesting though http://forum.doom9.org/showthread.php?t=164386

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s