You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-pix_fmt - forces the colorspace you wish to work in
Not usually required - ffmpeg will often choose the correct option for the codec(s) involed but some encoders can support multiple colorspaces so you sometimes need to be specific. Here are some common ones:
-pix_fmt yuv420p - same as DVD and BLu-ray footage. Common in most compressed streaming media. Use this for encoding for the web
-pix_fmt yuv422p - More chroma samples, used for common intermediate and editing codecs
-pix_fmt yuv444p - 'Lossless' colorspace used for high quality editing codec profiles when using raw footage.
-pix_fmt yuv444p10 - as above but using 10bits for the luma channel instead of 8. Better for VFX work - smoother gradients etc.
Resizing source video before encoding
Before scaling, set the rsize algorithm: -sws_flags spline or -sws_flags lanczos will do.
Then, resize either with the scale video filter: -filter:v scale
Examples:
Scale to a particular width, auto-calculate the appropriate height:
-vf scale=1280:-1
Scale to a particular height, auto-calculate the appropriate width:
-vf scale=-1:1080
Scale to fit into a 1920x1080 frame and add borders if needed (useful for DXnHD etc):
Choosing a video codec in ffmpeg generally uses the format -c:v followed by the codec
Here is a summary of the most important codecs for conversion:
libx264 - The open-source encoder for h264 encoding (mpeg4), usually for web distribution but also can be set as a high quality lossy intermediate codec for editing on some systems.
prores and prores_ks - ffmpeg's implementation of Apple's ProRes codec. Fairly industry standard for Final Cut usage - works in all pro editing systems. Main downside is the ffmpeg implementation is slow as an encoder so processing source may take longer than other options.
dxnhd - Avid's editing codec. Just as well supported as ProRes and encodes faster with ffmpeg, which is a plus. However, this is profile-based so will only allow certain resolution, fps and colorspace combinations. If you source isn't exactly 720p or 1080p or what have you you will need to add borders to be able to convert using this codec.
utvideo - Lossless codec, excellent quality but only really supported by Windows version of video editors. Can be sometimes slow to read making quick editing trickier but the compressed size is fairly similar to high quality lossy codecs!
mjpeg - low quality traditional format that reads and writes really fast so good as a proxy source for video editors that allow low-quality proxies to be used.
h264
The main aspects here are -crf which controlls quality (0 being lossless and 22 being the default). -g controls GOP length so setting this to 1 makes every frame a keyframe which is ideal for editing.
Lossless h264
-c:v libx264 -crf 0 -g 1
Lossy encoding with every frame a keyframe
-c:v libx264 -crf 16 -g 1
or, if you don't care about the file size that much and would rather it encode quicker:
-c:v libx264 -crf 14 -preset faster -g 1
16 is medium quality but higher numbers would be very good quality. The higher the number, the larger the file until you reach lossless.
ProRes
Note the -vendor ap10 part below is only needed if working with Final Cut, but it does no harm otherwise.
High Quality 4444 - usually overkill unless doing VFX work
Standard Quality 422 - or this if you are low on space and need something 'good enough'
-c:v prores_ks -profile:v 2 -vendor ap10
Proxy Quality - For proxy files only, looks crappy but edits fast and is small
-c:v prores_ks -profile:v 0 -vendor ap10
DNxHD
First look up the bitrate you need to set on this table based on the framesize, fps and desired quality level. For each there is a standard and a high quality version. The high quality version is preferred:
Project Format
Resolution
Frame Size
Bits
FPS
1080i / 59.94
DNxHD 220
1920 x 1080
8
29.97
220M
1080i / 59.94
DNxHD 145
1920 x 1080
8
29.97
145M
1080i / 50
DNxHD 185
1920 x 1080
8
25
185M
1080i / 50
DNxHD 120
1920 x 1080
8
25
120M
1080p / 25
DNxHD 185
1920 x 1080
8
25
185M
1080p / 25
DNxHD 120
1920 x 1080
8
25
120M
1080p / 25
DNxHD 36
1920 x 1080
8
25
36M
1080p / 24
DNxHD 175
1920 x 1080
8
24
175M
1080p / 24
DNxHD 115
1920 x 1080
8
24
115M
1080p / 24
DNxHD 36
1920 x 1080
8
24
36M
1080p / 23.976
DNxHD 175
1920 x 1080
8
23.976
175M
1080p / 23.976
DNxHD 115
1920 x 1080
8
23.976
115M
1080p / 23.976
DNxHD 36
1920 x 1080
8
23.976
36M
1080p / 29.7
DNxHD 45
1920 x 1080
8
29.97
45M
720p / 59.94
DNxHD 220
1280x720
8
59.94
220M
720p / 59.94
DNxHD 145
1280x720
8
59.94
145M
720p / 50
DNxHD 175
1280x720
8
50
175M
720p / 50
DNxHD 115
1280x720
8
50
115M
720p / 23.976
DNxHD 90
1280x720
8
23.976
90M
720p / 23.976
DNxHD 60
1280x720
8
23.976
60M
Then add the bitrate to this command (using 1080p 24fps as an example):
-c:v dnxhd -b:v 175M
UTVideo
UTVideo, being lossless, can generally handle any input format, so the command is simply:
-c:v utvideo
MJpeg
Where qscale is the quantizer to use, 1 being the highest. Still not great quality. For shitty proxy files you can drop qscale to 4 or lower to make small but ugly and fast files.
-c:v mjpeg -qscale 1
Audio Settings
Stripping Audio
Simply add this shorthand
-an
AAC (for mp4 video files)
Stereo Bitrates: 128k, 160k, 192k, 224k, 320k
224 is what iTunes uses if that gives any idea
-c:a aac -b 224k
Container Settings and Extension
You can determine a container format either by specifying it on the commandline with -f otherwise ffmpeg will use the filename to determine the container: