Bernat Guitart - Feb 2nd, 2022
Converting videos to different formats, sizes, qualities, cropping, trimming, adding intros and outros, watermarking, adding subtitles and a long list of day to day opeations are at your finger tips with a few terminal commands and the right tools to use.
For sure, the best and most used tool for video operations is FFMPEG, a more than 20-years old open-source tool that continues to be your best companion for these tasks.
What FFMPEG is?
FFMPEG is an open-source multimedia framework that can be used for recording, converting, and streaming videos. FFMPEG is a command-line program that runs in a console and has no user interface. This is a showstopper for many potential users that do not feel comfortable using a console window, and certainly FFMPEG is not the easiest and user-friendly software you will find.
On the bright side, it is free to use and install on Windows, MacOSX, GNU/Linux, Android etc. And this makes it a first-option for many higher-level software that use FFMPEG in the background.
What FFMPEG can do?
The list is so extense that it would probably be easier to answer what it can't do, but just as matter of examples this is a list of the most common uses cases for FFMPEG:
- Convert videos from almost any format to almost any format
- Extract video frames into separate images
- Trimming (cutting) the beginning or the end of a video
- Make a timelapse video from many pictures
- Add or remove audio tracks to a video
- Mix different audio streams into one
- Resize a video scaling up or down, or changing the aspect ratio
- Overlay videos, images or text
- Change the frame rate and the speed of a video
- Concatenate different videos one after another
- Create transitions between videos using fade-in, fade-out and other transitions
- Compress video file size by tuning certain parameters
- Improve video correcting brightness, color temperature, contrast, saturation
As said, the list could have 100+ items and it won't be complete, so you probably can assume that anything you imagine can be probably done with FFMPEG in some way.
To use FFMPEG you need to install it on your computer or on a server. There are ready-to-use versions of FFMPEG for the most common platforms like Windows, MacOSX and Linux, or if you have special needs you can compile FFMPEG from its source code.
Read the HOW-TO guide on How to install FFMPEG on your computer.
FFMPEG tools suite
FFMPEG comes with 3 command-line tools:
ffmpeg: used to edit/transform video or multimedia files
ffprobe: used to inspect a video or multimedia file
ffplay: used to play a multimedia file
In this course you will learn how to use
ffmpeg but I
will use (and recommend) playing the videos with VLC or Quicktime.
How to use FFMPEG
As previously said, FFMPEG is a tool with no Graphical User Interface (GUI) that receives parameters as input and generates files as output.
FFMPEG can be used in several ways:
- From the console command-line passing all input parameters
- From a command-line script (like
.batin Windows or
bashscripts in MacOSX and Linux
- From another program written in almost any language: Python, PHP, NodeJS, Go lang, C/C++, etc.
You must choose what is the best way for you based on your use case and for simplicity in this course we will use command-line parameters.
FFMPEG command-line structure
FFMPEG uses a quite strict and particular structure for receiving parameters that it's pretty simple in concept but that gets quite complicated to read as you add more and more parameters.
The basic command-line structure is:
ffmpeg [global-options] [[input-options] -i [input-file]] [output-options] [output-file]
global-options: related to global settings, for example, logging
input-options: apply to the input file just after
input-file: defines an input source
output-options: apply to the changes to be made to the output
output-file: defines the output file
Note: there can be any number of input sources, with their preceded input-options.
ffmpeg \ -y \ -loop 1 -t 2 \ -i image.png \ -pix_fmt yuv420p -vcodec libx264 \ output.mp4
- The red part are the global options
- The green part are the input options
- The blue part is the input file
- The orange part are the output options
- The magenta part is the output file
What sentence below better defines what FFMPEG is?
How video and audio files are organized?
The codec defines the way the stream is compressed
Transcoding is the action of...
Published on February 2nd, 2022