Recently I needed to create a timelapse for a project that I was working on and ran into the issue of encoding video footage from individually captured pictures. To prevent myself from running into this problem again I’m recording the solution to it here. My requirements on the project were that I wanted to encode the video in a high quality intermediate codec in 4k quality to enable editing down the line. I also wanted to do this using an open source solution if possible.
Fortunately, it turns out the open source multimedia program ffmpeg actually contains an open source Apple ProRes encoder. Unfortunately, to input image files, the application requires that they are labeled with a running sequence of numbers in the file name. IE “IMG_0001.jpg”, “IMG_002.jpg”… While many cameras do number images like this, mine skipped a couple of numbers which caused problems during encoding. I also had multiple shots in a single folder.
My first step was to separate out each of the shots into their own directories. I marked down the range of files from each shot by opening them up in an image viewer and moved them to the directories. Once that was done, I had to relabel all of the images with sequential numbers to enable ffmpeg to work its magic. This was achieved simply on linux with the following BASH script:
for i in *.JPG; do
new=$(printf “%04d.jpg” “$a”) #04 pad to length of 4
mv -i — “$i” “$new”
The actual command to perform the encoding is rather simple:
ffmpeg -f image2 -r 24 -start_number 0001 -i %04d.jpg -s 3840×2160 -vcodec prores -profile:v 3 .output.mov
-f image2 specifies that the input file format is jpeg
-r 24 tells the program to encode at a frame rate of 24 FPS
-start_number 0001 sets the index of the first picture to use
%04d.jpg is the filename of the input pictures. ffmpeg will replace %04d with a number padded with zeros to four characters (0001, 0002, 0003, …)
-s 3840×2160 is the resolution of the frame, 4k UHD in this case
-vcodec prores sets the codec to be Apple ProRes
-profile:v 3 is the profile used by the ProRes encoder:
From the ffmpeg manual there are the following options:
0 – “proxy”
1 – “lt”
2 – “standard”
3 – “hq”
output.mov, finally is the output filename
Executing this command in the folder containing my images from each shot generated video files encoded at about 1Gbit/S in Apple ProRes.