Before this article gives us a walkthrough on creating videos from images under a Linux operating system environment, it is important to understand the why before we engage the how.
Images Founded Videos
The concept of integrating images into videos is not rocket science as it logically takes a series of images to compose a video. Every video you watch; even your favorite YouTube videos are just a series of still images undergoing a very quick image-to-image transition. In-between these transitions is a black picture that enables the video being played to switch frames from one still image to the next one.
[ You might also like: How to Find Files Modified in Last 24 Hours in Linux ]
The image-to-image transition mechanism is too fast for the human eye to notice with optical illusion being one of the contributing factors. These images that define a created video are called frames. When you pause a playing video, you are actually looking at a frame (still image). It is the reason why a paused video might have blurry clarity in comparison to the one playing.
Measuring Videos Using Images
A frame rate depicts how many pictures transition in a single second. So if an image transitions after every 33 milliseconds, that video attributes to 30 frames per second which are somewhat 108,000 frames per hour. This concept should help you understand why 720p, 1080p, and 4K videos vary in size.
As exciting as this images-to-videos relationship is, this article guide needs to redirect its focus from advanced video editing concepts and help you transform your still images into videos.
Using ffmpeg for Images-to-Video Creation in Linux
This ffmpeg free software with its publicly available source code will help us achieve this article’s objective.
Choose one of the following installation options in relation to the Linux operating system distribution you are using.
Install FFmpeg in RHEL, CentOS, Rocky, and AlmaLinux
$ sudo dnf install epel-release $ sudo yum config-manager --set-enabled PowerTools $ sudo yum-config-manager --add-repo=https://negativo17.org/repos/epel-multimedia.repo $ sudo dnf install ffmpeg
Install FFmpeg in Fedora Linux
$ sudo dnf install \ https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \ https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm $ sudo dnf update $ sudo dnf install ffmpeg
Install FFmpeg in Debian, Ubuntu, and Mint
$ sudo apt-get install sshpass [On ]
Install FFmpeg in Arch Linux
$ sudo pacman -S git $ git clone https://aur.archlinux.org/snapd.git $ cd snapd $ makepkg -si $ sudo systemctl enable --now snapd.socket $ sudo ln -s /var/lib/snapd/snap /snap $ sudo snap install ffmpeg
Install FFmpeg in OpenSUSE Linux
$ sudo zypper addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_15.2 snappy
Swap out openSUSE_Leap_15.2 with your openSUSE version e.g. openSUSE_Tumbleweed, openSUSE_Leap_15.0, or openSUSE_Leap_15.1.
Next, run the series of commands to install it.
$ sudo zypper --gpg-auto-import-keys refresh $ sudo zypper dup --from snappy $ sudo zypper install snapd $ sudo systemctl enable snapd $ sudo systemctl start snapd
The following additional commands apply to Tumbleweed users.
$ sudo systemctl enable snapd.apparmor $ sudo systemctl start snapd.apparmor
Finally, install ffmpeg
$ sudo snap install ffmpeg
How to Use FFmpeg for Images-to-Video Creation in Linux
Coming up with time-lapse movies and stop-motion photography are some key benefits of creating a video from a series of provided still images.
Video Images Preparation
The naming convention of your input images should be sequential since ffmpeg follows a string-matching rule to properly identify and line up these images.
Your image file-naming convention should adhere to either of the following three ffmpeg supported filename patterns.
- With leading zeroes – The ffmpeg command segment ‘filename-%03d.png’ will look for image files with names ranging from filename-001.png to filename-999.png.
- Without leading zeroes – The ffmpeg command segment ‘filename-%d.png’ will look for image files with names ranging from filename-1.png to filename-999.png.
- Without a regular naming pattern – The ffmpeg command segment ‘filename-*.png’ will not follow any sequential order while looking for image files.
Creating Video from Images in Linux
The ffmpeg syntax for images-to-videos creation for image filenames with leading zeroes looks something like the following:
$ ffmpeg -framerate 10 -i filename-%03d.png output.mp4
From the above command syntax, you can set the frame rate to the desired figure and specify the output video file name.
Let us try to create a video from the following images.
Since the naming convention of these image files is sequential but without leading zeroes, we will use the following ffmpeg command:
$ ffmpeg -framerate 25 -i image-%d.png output.mp4
We have set the frame rate to 25.
The expected output video file should be visible:
When the images you are converting to videos do not need to follow a sequential stream; images with random names like image-00.png, image-10.png, and image-30.png, you can use the glob matching pattern as demonstrated by the following syntax:
$ ffmpeg -framerate 10 -pattern_type glob -i "image-*.png" output.mp4