Lately i've posted a lot of questions about how to use ffmpeg. It's pretty clear to me that I am missing some sort background in video encoding and was wondering if any of my fellow superusers had any good resources for studying up on video encoding. What do I need to understand before I can use ffmpeg effectively?
Read "Mark Pilgrim – A Gentle Introduction to Video Encoding": "Container Formats", "Lossy Video Codecs", "Lossy Audio Codecs", "Captioning" and ...– Cristian CiupituAug 4, 2014 at 23:48
... "Constraints".– Cristian CiupituAug 4, 2014 at 23:49
Video formats and general guidelines
First of all, you need to understand which different codecs and formats exist, and what they are typically used for:
What is a Codec (e.g. DivX?), and how does it differ from a File Format (e.g. MPG)?
You should also look into what makes up video quality in a more general fashion, e.g. how does bit rate, frame rate, or picture size affect the quality?
What do the numbers 240 and 360 mean when downloading video? How can I tell which video is more compressed?
Let's use FFmpeg…
You should know how to install the latest version of FFmpeg. The latest versions always include up-to-date bugfixes and new functions. People often make the mistake to use the old versions bundled with their distributions or that they have on some server – these often just do not work.
- Linux: There are static builds from Burek and from Relaxed. Download, extract, use it. You can also install FFmpeg from the Git sources. There are extensive tutorials for Ubuntu and CentOS available.
- Windows has static builds online.
- OS X offers a formula for Homebrew installed with
brew install ffmpegafter installing Homebrew itself.
Read the FFmpeg documentation, at least the general options, and learn the basic command line switches.
Also check out our Super User blog entry: FFmpeg: The ultimate Video and Audio Manipulation Tool for an always up-to-date guide on transcoding with FFmpeg and a few examples as well as a large link collection at the end.
Encoding with x264
The best free video encoder out there today is x264, and using
libx264, FFmpeg can use it too. You should install x264 and read the help with
x264 --fullhelp. x264 has plenty of options, which are mapped to FFmpeg.
For encoding, you will then be able to use the presets x264 offers. They are accessible through the FFmpeg options too. There are some main options which come in handy. Read the x264 encoding guide on the FFmpeg wiki. In short, this is what you can use:
-profile:vspecifies the h.264 profile to be used, for example
high, which could be used for all kinds of video playing software, or
baseline, which restricts the video to use features that work on a mobile phone or iPod only.
-presetspecifies the encoding presets for speed.
fastwill give you faster results, but worse compression, for example. These range from
ultrafast. Default is
-tuneoffers options for tweaking the output based on the input files, e.g. animated movies with
animationor normal movies with
-crfsets the Constant Rate Factor, the #1 method to be used when trying to tweak the result quality. Read up on it here. Use a value between 18 and 27, where lower means better quality. Default is 23.
You can install a video encoder like Handbrake and see which options it uses. Learn by doing, and try to read up on what all the parameters do.