Converting GoPro Timelapse Images to a Video with Imagemagick and ffmpeg
Recently, a crane was built in front of where I live and I wanted to capture a timelapse of the construction process. It’s been a while since I’ve made a timelapse with my GoPro and I wanted to document a workflow for future use. Here’s the finished result:
Cropping for Aspect Ratio
GoPro images are
The standard aspect ratio for YouTube on a computer is
Let’s crop the images to them
16:9, giving us a size of
In the terminal, navigate to your images folder and run the following:
# create a dir for the cropped images mkdir out # find all images, iterate through, and crop for F in $(find img -iname "*.jpg"); do convert $F -crop 4000x2250+0+375 out/$(basename $F); done
The above command assumes that the GoPro images are in the
The crop position assumes a centred
Note that the XY offset for the cropping can be modified using the
-crop WxH+X_OFFSET+Y_OFFSET term above.
Rename Files to Sequential Numbers
In the next step, we’ll merge the images into a video using
However, we need the files to be sequentially numbered without gaps.
An example GoPro image filename looks like this:
While they already have their own numbering convention, there are two problems:
- Numbering does not start at an index of
- There may be gaps in the numbering if images are deleted or edited out.
Instead, we can assume that the alphanumerical order is true (i.e., sort by filename). Navigate to the images directory and run the following:
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
ls: lists the files
cat -n: adds line numbers
while loop: reads the resulting numbered list of files line by line
n: line number
mv: performs the rename
Convert to a Video
ffmpeg, we can convert the cropped and sequentially numbered images to a video.
If a GIF is your desired end result, it’s a lot more efficient (in terms of both memory, size, and speed) to start with a high-quality video and then convert to GIF, rather than going directly to GIF from a series of images.
From the root directory, run the following:
ffmpeg -framerate 30 -i out/%d.JPG -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4