Creating a 4K Time-Lapse Video using Open-Source, Cross-Platform Tools
Jul 28, 2015
As part of the Spark Festival London 2015 I will be demonstrating a 3D printer making a copy of itself. To get things started I had to build a 3D printer (RepRap Huxley Duo) myself and thought i’d document the process and create a timelapse video. Just to make my life a bit more interesting, I aimed to use only cross-platfrom, open-source software.
I set up my camera (Sony A5100) on a little tripod and had it take a photo every minute I was working on the printer. The following is the resulting timelapse. To see how I made the movie from the image files read on.
Step 1: Alignment
The photographs were taken in a number of different sessions as I was doing the build in the evenings and at the weekend. This meant that the photographs from one session did not align exactly with the next session as shown in the following gif (made from the first picture from each session). Look at the top left corner of the table to see it jump around. To create a .gif from these images I used ImageMagick (IM) like follows (we’ll be seeing a lot more of ImageMagick!)
I calculated the offset of each session’s images from the first by adding each image to a layer in GIMP, reducing the opacity, moving it until it looked right and recording the offset. The result was an improvement but not perfect.
To test the new alignment I moved the first images by their offset, this was done using IM like so:
This is the result:
We can see that there are now small black areas in the bottom right of the image that we need to crop off. 60 pixesls off X and Y should do it:
So that works for the tests, now we apply the alignment and crop to each photo in the respective sessions, again using IM but all wrapped in a nice bit of bash..
Step 2: Colour Adjustment
We can see in this first gif that the brightness really drops near the end of the session. The photographs were taken using the same settings as it got dark outside the photos becames really underexposed!
We can fix this (to an extent) by bumping up the levels in the darker images. To do this I used the this fantastic IM script, Autolevel, thanks Fred!
Now to get all the levelled frames together in a folder and make a test movie using ffmpeg:
Step 3: Cropping for a nice smooth zoom
To make the time-lapse more visually interesting I wanted to have a slow zoom in to the more interesting area of the frame (the printer) over the course of the time-lapse. I did this by cropping the images by a slowly increasing amount. As long as I kept the vertical resolution over 2160 pixels I could still resize to my desired 4k resolution.
For this I used a bash script like so:
Now I have to resize all of the images to match my desired resolution:
Step 4: Adding the elapsed time and ‘progress bar’
I wanted to add text displaying the elapsed time and the current ‘task’ such as ‘X Axis Assembly’ to the frames. I hacked this together in Python, its really not pretty and the if/else statement is truly horrible.
The interesting bit is where I write the current time (basically the frame number as it was one frame per minute mod 60) and the current stage. I write the full ‘stage’ string at just under 50% alpha transparency and then write a number of letters of the same string at full opacity as the we progress through the task.
I’m really happy with how this works. I think it gives a good feeling of the speed of doing each task in quite a concise way (I especially like the speed of fitting the heat bed assembly).
Step 5: Intro and Outro
I liked the effect so I thought I would use it to create an intro and an outro using the same effect. As I already had the python code this was surprisingly easy.
I just used a slight variation of this script for the outro using a different base image (the last frame) and reversing the order.
To create a 4K video from a set of frames (into, main or outro) we just navigate to the folder and use the following command:
Step 6: Putting it all together
To join the videos we use still use ffmpeg. We create a list of the files to be joined and then put them in a text file called ‘mylist4k.txt’ or whatever you would like to call it:
We then use the ‘concat’ flag with ffmpeg and pass it our list.
Step 7: Adding Audio
Now the last piece was to add some music, I bought a jaunty tune from AudioJungle and downloaded it as an mp3. Then to add the audio to the full video we just use ffmpeg as follows:
Thats it! Job done! Here is the end result one more time, make sure to select 2160p on the quality settings!