If you don’t know it already, ffmpeg is a software that does video and audio conversion and editing using filters. It’s the one which supports the greatest number of different codecs. If you already used VLC, then you know a bit ffmpeg: VLC uses ffmpeg to decode as many videos as possible.
But before making videos, I need to tell you some concepts so you don’t get lost in the way.
Video concepts: how images can work in a video
It’s not really hard to integrates images in a video. And there’s a reason: videos are based on a series of images. Let me explain.
A video (even a YouTube video) is a suite of still images that changes quickly. In cinema and movie theaters, between each image there’s a black picture because the mechanism has to switch frame and was too slow. But it’s not noticeable by human eye because the mechanism is fast enough and because of an optical illusion.
But computers don’t have this problem. LCD screens just keep displaying the last image. Anyway, you can in fact extract a independent image from every image of a video. When an image comes from a video, it’s called a frame. That’s exactly what you see when you pause a video – and when you do so faces generally doesn’t look good!
Generally, videos from United States a contains 30 frames per second – realize a bit. It’s 1,800 frames per minute, 54,000 frames per half hour of video, or 108,000 frames per hour. That’s a lot and that’s how you wonder sometimes how a single image can weight 1 MiB but one minute of 1080p video can weight only 15 MiB.
The number of pictures per second is called the frame rate. At 30 frames per second, you change image every 33 milliseconds. So concretely, if you wanted to do one minute of video based solely on your images, you would need to have 1,800 JPG or PNG files per minute.
That’s useful if you want to do advanced video editing without using video tools: you just have to build images for each frame with your effects and then you can bundle it in a video. But sometimes you want a still image to last because, well, you want a still image in video.
Okay, now, time to install ffmpeg.
Install ffmpeg on Linux
Depending of your distribution, installing ffmpeg can be easy or a little tricky. It’s a free software with source code publicly available, but as it can decode or encode patented formats like MP4, some distributions excludes it from their repositories. For example, in Red Hat Enterprise Linux, CentOS and Fedora, you need RPMFusion because of patents. Moreover, all Debian versions and Ubuntu before 16.04 is distributing a false version of ffmpeg based on a illegitimate fork.
But before hurrying in installing it, maybe the right version already installed? Let’s test:
ffmpeg version X.XXXXXXXX Copyright (c) 2000–2018 the FFmpeg developers
If after the copyright you do see “the FFmpeg developers”, you have the original version of FFMpeg, you need to do nothing. However, if you see:
ffmpeg version X.XXXXXXXX Copyright (c) 2000–2018 the Libav developers
Then it means you’re using a fork of ffmpeg called Libav. Debian and older versions of Ubuntu silently substitute FFMpeg with Libav. If it tells you it’s deprecated, please ignore it, that’s misleading. If you have the fork installed it’s time to remove your version of false ffmpeg and then follow the guide below to install the right version. Probably like this:
So now you may haven’t it installed yet or you have the wrong version, time to install it!
In Fedora, Red Hat Enterprise Linux (RHEL) and CentOS, go to https://rpmfusion.org/Configuration and enable free RPMFusion repository on your computer. Then, if you’re in Fedora, do:
And for CentOS & Red Hat Enterprise Linux, do:
That’s all for Fedora and Red Hat based systems, it’s installed.
In all versions of Debian (and all derivatives) and Ubuntu before 16.04, you need to get FFMpeg static build from the official website. Go to https://ffmpeg.org/download.html#build-linux and below “Linux Static Builds”, click on “32-bit and 64-bit for kernel 2.6.32 and above”. Then, below “release: X.X.X”, download the appropriate archive, extract it and you can launch the executables located in extracted folder via CLI.
For the ones using Ubuntu 16.04 and above, it’s easier, just do:
Phew! Finally we should be good to go! Before going on, test a last time with:
ffmpeg version X.XXXXXXXX Copyright (c) 2000-2018 the FFmpeg developers
Create videos from many images
So, for our first example, we’ll create a video from Images where each image represents a frame that will be displayed for 33 milliseconds. Let me show you first the command.
** MP4 and H.264 are patented codecs, please check if you have the right to encode with it. **
-pix_fmt yuv420p -crf 28 -an "Penguins.mp4"
OK so how that works? For this command to work, you need to have many frames where each frame is a file like Penguins – 00043.png. This command will then combine all frames in order at a rate of 30 FPS. So, Penguins – 00043.png comes before Penguins – 00044.png in the video and ffmpeg will respect that. So if you have 120 frames, your video will have a 4 seconds duration.
There’s few requirements about format, width and height for frames to work. If you don’t follow these rules, ffmpeg may ignore some images or cancel video creation process. So:
- All frames in a same video must share:
- Width & height
- Color depth
- Frames should be in a standard video size such as:
- 640 ✕ 360 (360p)
- 853 ✕ 480 (480p)
- 1280 ✕ 720 (720p)
- 1920 ✕ 1080 (1080p)
- 4096 ✕ 2306 (4K)
- Prefer frames in PNG rather than JPG
- Avoid transparency or alpha in PNG format
The command will then take some time to convert the video, optimize its performance and make you a MP4 file named Penguins.mp4.
Now, you may want to have, well, a still image remaining for more than 33 milliseconds. In this case, your video is more a slideshow and it’s not the same affair. To do so, you may first give a slower framerate for the input and then tell ffmpeg to duplicate frames in output. No, YouTube and Vimeo won’t really appreciate a 0.5 FPS video even if you change your image every 2 seconds.
Let’s rather do that:
-pix_fmt yuv420p -crf 28 -an "Penguins.mp4"
There we go! ffmpeg will make each of your images appear for 5 seconds but in a 30 FPS video. Don’t worry about the duplicate frames warning: it’s what you want.
Now, you’re – the new Spielberg – able to create your own videos. You can do a simple slideshow or prepare a video frame by frame using an image editor such as GIMP, but you can also benefit from the large set of effects and codecs you can find in ffmpeg.
Take the time to experiment by yourself – you’re an artist, after all – and create a video that will do millions of views in YouTube!