Categories
Uncategorized

Using ffmpeg to convert all images in a folder to video

I take lots of photos on my phone, a daily record of the mundane and notable. These photos sit in folders, mostly unlooked at. Here’s one way to grok what you’ve been taking pictures of: make a video which shows them at a rate of 3 per second.

Cribbing from this:
superuser.com: How to transform all the images from the current directory to a video in FFmpeg?
and this:
superuser.com: Resizing videos with ffmpeg/avconv to fit into static sized player (comment)

The thing that makes this slightly more complex is that the photos are different sizes (some are portrait, some are landscape) and I want them to maintain their aspect ratio in the video, which means padding the portrait photos with some black space for the output.

In a terminal define output height and width variables (so, for photos from my phone):


width=3264
height=2448

Then

ffmpeg -framerate 3 -pattern_type glob -i '*.jpg' -vf "scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2" video.mp4

Click here to get a breakdown of what this is doing via explainshell.com. People with longer attention spans may want to reduce the framerate (3 per second is nice if you have lots of photos of the same scene, but a bit quick for single photos).

Obviously I have assumed you are using linux and have ffmpeg installed