Combine images into a strip



This is the start of a series of software & coding oriented tutorials that I would like to share with you.

I hope these tutorials will help put aspects of technology to work for your creativity.

In this first tutorial, we will see how to assemble images into a strip, using the command line tool ffmpeg, a powerful cross-platform tool for manipulating videos, images and audio.

Here’s a video describing the process through a screencast :

A little parenthesis to mention that the background music in this video is a creation of mine – My Dj/Producer’s name is Franck Goss. Track’s title : Sun Flow (Original Cut).

There are several ways to install ffmpeg, depending on your operating system.

Here’s a useful link for installing it on main operating systems :

https://trac.ffmpeg.org/wiki/CompilationGuide

More info about ffmpeg at https://ffmpeg.org.

Operating system used in this tutorial : macOS Catalina.

Here is one easy way to install ffmpeg on macOS :

Via the Terminal application, type the following command :

brew install ffmpeg

For the sake of simplicity, we will put all the source images in one folder, let’s say the path of this folder is :

/Users/johndoe/Desktop/my_cool_images

(where johndoe is your macOS session username)

Via the Terminal we will go to this folder using the following command :

cd /Users/johndoe/Desktop/my_cool_images


And now, let’s generate image strips ! In the following examples, the image strips will be generated in the same folder as the source images.


– Sample command to create a horizontal strip :

(important : The images must have the same height *)

ffmpeg -i 004.png -i 001.png -i 003.png -i 002.png -filter_complex hstack=inputs=4 output.png

(The ‘inputs’ variable corresponds to the number of images)

– Sample command to create a vertical strip :

(important : The images must have the same width **)

ffmpeg -i 004.png -i 001.png -i 003.png -i 002.png -filter_complex vstack=inputs=4 output.png

(The ‘inputs’ variable corresponds to the number of images)

* Sample command to change the height of an image to 400 pixels while preserving its aspect ratio :

ffmpeg -i 001.jpg -vf "scale=-1:400" output_resized_height.jpg

** Sample command to change the width of an image to 400 pixels while preserving its aspect ratio :

ffmpeg -i 001.jpg -vf "scale=400:-1" output_resized_width.jpg

Enjoy !

Best Regards.

Franck Mallouk, aka Dj Franck Goss

Franck Mallouk profile picture

www.oniricforge.com