wiki:

Encode

/

AV1


Version 14 (modified by Ewout, 10 days ago) (diff)

Add color info passing for HDR

libaom AV1 Encoding Guide

libaom-av1 is the AOMedia video encoder for AV1, an open source & royalty-free video codec. libaom-av1 can save about 30% bitrate compared to VP9 and H.265 / HEVC, and about 50% over H.264, while retaining the same visual quality.

To install FFmpeg with support for libaom-av1, look at the Compilation Guides and compile FFmpeg with the --enable-libaom option.

libaom offers the following rate-control modes which determine the quality and file size obtained:

  • Constant quality
  • Constrained quality
  • 2-pass average bitrate
  • 1-pass average bitrate

For a list of options, run ffmpeg -h encoder=libaom-av1.

Note: AV1 encoding is very slow in comparison to VP9 or H.264, and considered experimental at this stage. Hence the use of -strict experimental (or the alias -strict -2) is necessary.

Constant Quality

libaom-av1 has a constant quality (CQ) mode (like CRF in x264 and x265) which will ensure that every frame gets the number of bits it deserves to achieve a certain (perceptual) quality level, rather than encoding each frame to meet a bit rate target. This results in better overall quality. If you do not need to achieve a fixed target file size, this should be your method of choice.

To trigger this mode, you must use a combination of -crf and -b:v 0. -b:v MUST be 0.

ffmpeg -i input.mp4 -c:v libaom-av1 -crf 30 -b:v 0 -strict experimental av1_test.mkv

The CRF value can be from 0–63. Lower values mean better quality and greater file size.

Constrained Quality

libaom-av1 also has a constrained quality (CQ) mode that will ensure that a constant (perceptual) quality is reached while keeping the bitrate below a specified upper bound or within a certain bound. This method is useful for bulk encoding videos in a generally consistent fashion.

ffmpeg -i input.mp4 -c:v libaom-av1 -crf 30 -b:v 2000k -strict experimental output.mkv

The quality is determined by the -crf, and the bitrate limit by the -b:v where the bitrate MUST be non-zero.

You can also specify a minimum and maximum bitrate instead of a quality target:

ffmpeg -i input.mp4 -c:v libaom-av1 -minrate 500k -b:v 2000k -maxrate 2500k -strict experimental output.mp4

Two-Pass

In order to create more efficient encodes when a particular target bitrate should be reached, you should choose two-pass encoding. For two-pass, you need to run ffmpeg twice, with almost the same settings, except for:

  • In pass 1 and 2, use the -pass 1 and -pass 2 options, respectively.
  • In pass 1, output to a null file descriptor, not an actual file. (This will generate a logfile that ffmpeg needs for the second pass.)
  • In pass 1, you need to specify an output format (with -f) that matches the output format you will use in pass 2.
  • In pass 1, you can leave audio out by specifying -an.
ffmpeg -i input.mp4 -c:v libaom-av1 -strict experimental -b:v 2M -pass 1 -an -f matroska /dev/null && \
ffmpeg -i input.mp4 -c:v libaom-av1 -strict experimental -b:v 2M -pass 2 -c:a libopus output.mkv

Note: Windows users should use NUL instead of /dev/null and ^ instead of \.

Average Bitrate (ABR)

libaom-av1 also offers a simple "Average Bitrate" or "Target Bitrate" mode. In this mode, it will simply try to reach the specified bit rate on average, e.g. 2 MBit/s.

ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 2M -strict experimental output.mkv

Use this option only if file size and encoding time are more important factors than quality alone. Otherwise, use one of the other rate control methods described above.

Controlling Speed / Quality

-cpu-used sets how efficient the compression will be. Default is 1. Lower values mean slower encoding with better quality, and vice-versa.

Chroma subsampling / HDR

If you want to use different chroma subsampling formats such as 4:2:2 or 4:4:4 you can use -vf format=.

For example if you want to encode in 8-bit 4:4:4:

ffmpeg -i input.mp4 -c:v libaom-av1 -strict experimental -vf format=yuv444p output.mkv

Combined with a scaling option you can use it to downscale a 2160p 4:2:0 video to 1080p 4:4:4 for example:

ffmpeg -i input.mp4 -c:v libaom-av1 -strict experimental -vf "format=yuv444p,scale=iw/2:ih/2" output.mkv

Most used formats: 8-bit 4:0:0 gray, 8-bit 4:2:0 yuv420p, 8-bit 4:2:2 yuv422p, 8-bit 4:4:4 yuv444p, 10-bit 4:0:0 gray10le, 10-bit 4:2:0 yuv420p10le, 10-bit 4:2:2 yuv422p10le, 10-bit 4:4:4 yuv444p10le. View all the different subsampling formats with ffmpeg -pix_fmts

When encoding in HDR it's necessary to pass through color information; -colorspace, -color_trc and -color_primaries. For example, Youtube HDR uses

-colorspace bt2020nc -color_trc smpte2084 -color_primaries bt2020

More Info

More info about AV1 can be found here: