conversion

In case anyone cares, this is what I had to do to convert the movies from my camera to one single time-lapsed / frame decimated movie.

first extract frames:

ffmpeg -i FILE0002.MOV -r 1 -f image2 frames2/fr-%06d.png

-i : input file, ffmpeg will autodetect format
-r : the target frame rate, 1 frame / sec
-f : output format
the output file name takes the standard printf format for serially numbered images

I did this to each of the four files I had and ended up with four big piles of images. The numbering started from 000001 each time so I wrote a little script to renumber files as needed and move them into the appropriate directory. I used python because that’s how I do but I’m sure a sufficiently clever person could use the shell or the scripting language of their choice. I’m not going to put that in here because it is shameful.

Now I have a single very big pile of images.
I want to use the H.264 encoder to make an mp4 of high quality. I want to do this because I don’t know that youtube will mangle my pretty encoding when I give them my file. So it goes.

ffmpeg -r 30 -i allframes/fr-%06d.png -vcodec libx264 -vpre max -b 2048k -threads 0 mov1.mp4

-r : target frame rate, 30 frames / sec
-i : input files with the requisite printf format token
-vcodec : use libx264 to encode*
-vpre : use the x264 preset configuration ‘max’**
-b : 2048k video bit rate
-threads : 0 means use as many threads as it wants

*When I first tried this I ended up with an error “Unknown encoder ‘libx264′”. This is because Ubuntu doesn’t install libx264 by default. You have to go and uninstall libavcodec52 and install libavcodec-extra-52.

** apparently a couple of years ago it was decided that video encoding is hard and you needed to have a base config to work from. -vpre loads a preset video codec options set and then subsequent options you provide override values in that config. So, this uses a max quality option set and then sets the video bit rate to 2Mb/s which is pretty good quality for a 480p 30fps video.

So, this takes about three and a half hours of 60fps 848×480 video and smushes it down to a little under eight minutes of 30fps 848×480 video. Tada!

Leave a Reply