FFmpeg Encoding and Editing Course PDF
FFmpeg Encoding and Editing Course PDF
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 1/56
4/15/2020 FFmpeg Encoding and Editing Course
ABOUT ME
Video quality and Quality of Experience researcher
PhD student and research assistant at Technische
Universität Ilmenau
Contact:
werner.robitza@gmail.com
http://slhck.info
@slhck
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 2/56
4/15/2020 FFmpeg Encoding and Editing Course
GOALS
This course should cover:
Basic concepts
Installing ffmpeg and tools
Encoding videos
Appling filters
Analyzing videos
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 3/56
4/15/2020 FFmpeg Encoding and Editing Course
REQUIREMENTS
These slides
ffmpeg, ffprobe and ffplay installed (it will be
explained)
Some sample videos, example: Big Buck Bunny
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 4/56
4/15/2020 FFmpeg Encoding and Editing Course
RESOURCES
If you need sample videos for testing, see overview
from VQEG
(Video Quality Experts Group):
https://www.its.bldrdoc.gov/vqeg/video-datasets-and-
organizations.aspx
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 5/56
4/15/2020 FFmpeg Encoding and Editing Course
INTRODUCTION TO FFMPEG
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 6/56
4/15/2020 FFmpeg Encoding and Editing Course
ImageMagick
MLT Framework
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 7/56
4/15/2020 FFmpeg Encoding and Editing Course
TOOLS
FFmpeg contains:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 8/56
4/15/2020 FFmpeg Encoding and Editing Course
(libav*))
ABOUT THE LIBRARIES (libav*
libavformat: Reads and writes container formats
(AVI, MKV, MP4, …)
libavcodec: Reads and writes codecs (H.264,
H.265, VP9, …)
libavfilter: Various filters for video and audio
... and many more
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 9/56
4/15/2020 FFmpeg Encoding and Editing Course
ARCHITECTURE
Simplfied overall architecture:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 10/56
4/15/2020 FFmpeg Encoding and Editing Course
INSTALLATION / COMPILATION
Installation Pro Con
Method
Building from Offers all Takes time, harder
source options, to update
tools,
codecs
Downloading Easy and Does not offer all
static build fast encoders, manual
update necessary
Installing from Easy and Does not always
package manager fast offer latest version
(e.g., apt-get) or all encoders
Get source code and static builds from:
http://ffmpeg.org/download.html
Building on Windows: https://github.com/jb-
alvarado/media-autobuild_suite
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 11/56
4/15/2020 FFmpeg Encoding and Editing Course
GETTING HELP
Places to get help:
📖 Documentation: https://ffmpeg.org/ffmpeg-
📖 Wiki: http://trac.ffmpeg.org/wiki
all.html
📖 IRC: #ffmpeg
✉ Mailing list:
https://lists.ffmpeg.org/mailman/listinfo/ffmpeg-
user/
🌐 Stack Overflow: https://stackoverflow.com/ and
use #ffmpeg
🌐 Super User: http://superuser.com/ and use
#ffmpeg
… or ask me
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 12/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 13/56
4/15/2020 FFmpeg Encoding and Editing Course
CONTAINER FORMATS
Containers contain media data. Typical examples:
$ ffmpeg -formats
File formats:
D. = Demuxing supported
.E = Muxing supported
--
D 3dostr 3DO STR
E 3g2 3GP2 (3GPP2 file format)
E 3gp 3GP (3GPP file format)
D 4xm 4X Technologies
E a64 a64 - video for Commodore 64
D aa Audible AA format files
...
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 14/56
4/15/2020 FFmpeg Encoding and Editing Course
CODECS
CODEC = Coder / Decoder
Specification on how to code and decode video,
audio, …
Usually not a specification on how to encode /
compress data
Sometimes “codec” == actual encoding/decoding
software
$ ffmpeg -codecs
Codecs:
D..... = Decoding supported
.E.... = Encoding supported
..V... = Video codec
..A... = Audio codec
..S... = Subtitle codec
...I.. = Intra frame-only codec
....L. = Lossy compression
.....S = Lossless compression
-------
D.VI.. 012v Uncompressed 4:2:2
D.V.L. 4xm 4X Movie
D.VI.S 8bps QuickTime 8BPS vid
.EVIL. a64_multi Multicolor charset
.EVIL. a64_multi5 Multicolor charset
D.V..S aasc Autodesk RLE
D.VIL. aic Apple Intermediate
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 15/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 16/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 17/56
4/15/2020 FFmpeg Encoding and Editing Course
ENCODERS
Encoders are the actual software that outputs a codec-
compliant bitstream
Encoders can vary in quality and performance, some
are better than others (and some are free, some are
not)
Examples:
→ lots of competition
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 18/56
4/15/2020 FFmpeg Encoding and Editing Course
$ ffmpeg -encoders
Encoders:
V..... = Video
A..... = Audio
S..... = Subtitle
.F.... = Frame-level multithreading
..S... = Slice-level multithreading
...X.. = Codec is experimental
....B. = Supports draw_horiz_band
.....D = Supports direct rendering method 1
------
V..... a64multi Multicolor charset f
V..... a64multi5 Multicolor charset f
V..... alias_pix Alias/Wavefront PIX
...
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 19/56
4/15/2020 FFmpeg Encoding and Editing Course
PIXEL FORMATS
Representation of raw pixels in video streams
Specifies order of luma/color components and
chroma subsampling
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 20/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 21/56
4/15/2020 FFmpeg Encoding and Editing Course
GENERAL SYNTAX
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 22/56
4/15/2020 FFmpeg Encoding and Editing Course
Explanation:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 23/56
4/15/2020 FFmpeg Encoding and Editing Course
TRANSCODING BACKGROUND
From http://ffmpeg.org/ffmpeg-all.html:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 24/56
4/15/2020 FFmpeg Encoding and Editing Course
Examples:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 25/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 26/56
4/15/2020 FFmpeg Encoding and Editing Course
SETTING QUALITY
The output quality depends on encoder defaults and
the source material
Do not just encode without setting any quality level!
Generally: You need to choose a target bitrate or
quality level
Target bitrate depends on the video genre, size and
framerate
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 27/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 28/56
4/15/2020 FFmpeg Encoding and Editing Course
WHAT IS CRF?
CRF = Constant Rate Factor
Maintain constant quality across the entire encode
Good for storing video at fixed quality if file size is
not important
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 29/56
4/15/2020 FFmpeg Encoding and Editing Course
See https://trac.ffmpeg.org/wiki/Encode/H.264
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 30/56
4/15/2020 FFmpeg Encoding and Editing Course
RATE CONTROL
Different kinds of rate control:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 31/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 32/56
4/15/2020 FFmpeg Encoding and Editing Course
For example:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 33/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 34/56
4/15/2020 FFmpeg Encoding and Editing Course
CHANGING FRAMERATE
Simple way to change the framerate by dropping or
duplicating frames:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 35/56
4/15/2020 FFmpeg Encoding and Editing Course
STREAM MAPPING
Each file and its streams have a unique ID, starting with
0.
Examples:
See: http://trac.ffmpeg.org/wiki/Map
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 36/56
4/15/2020 FFmpeg Encoding and Editing Course
SIMPLE FILTERING
ffmpeg has lots of video, audio, subtitle filters:
-filter:v <name>=<option1>=<value1>:<option2>=<v
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 37/56
4/15/2020 FFmpeg Encoding and Editing Course
SCALING
Scale to 320×240:
More tips:
http://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20
https://superuser.com/questions/547296/
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 38/56
4/15/2020 FFmpeg Encoding and Editing Course
PADDING
Add black borders to a file, e.g. 1920×800 input to
1920×1080:
Note that:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 39/56
4/15/2020 FFmpeg Encoding and Editing Course
FADING
Simple fade-in and fade-out at a specific time for a
specific duration.
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 40/56
4/15/2020 FFmpeg Encoding and Editing Course
DRAWING TEXT
Complex system for printing text on video:
See: http://ffmpeg.org/ffmpeg-all.html#drawtext-1
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 41/56
4/15/2020 FFmpeg Encoding and Editing Course
COMPLEX FILTERING
Complex filters have more than one in- and/or output:
Steps:
See: http://ffmpeg.org/ffmpeg-all.html#Filtergraph-
syntax-1
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 42/56
4/15/2020 FFmpeg Encoding and Editing Course
CONCATENATING STREAMS
Decode three video/audio streams and append to one
another:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 43/56
4/15/2020 FFmpeg Encoding and Editing Course
TIMELINE EDITING
Enable filters only at a specific point in time.
Example:
See: http://ffmpeg.org/ffmpeg-all.html#Timeline-
editing
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 44/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 45/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 46/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 47/56
4/15/2020 FFmpeg Encoding and Editing Course
GENERAL CONCEPTS
ffprobe <input>
[-select_streams <selection>]
[-show_streams|-show_format|-show_frames|-sho
[-show_entries <entries>]
[-of <output-format>]
Explanation:
See:
https://ffmpeg.org/ffprobe.html
http://trac.ffmpeg.org/wiki/FFprobeTips
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 48/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 49/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 50/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 51/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 52/56
4/15/2020 FFmpeg Encoding and Editing Course
More info:
http://trac.ffmpeg.org/wiki/Debug/MacroblocksAndMo
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 53/56
4/15/2020 FFmpeg Encoding and Editing Course
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 54/56
4/15/2020 FFmpeg Encoding and Editing Course
SUMMARY
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 55/56
4/15/2020 FFmpeg Encoding and Editing Course
SUMMARY
You should have learned how to:
file:///home/amaranth/Desktop/ffmpeg-encoding-course-master/docs/index.html#/8 56/56