Skip to content

Instantly share code, notes, and snippets.

@mrintrepide
Last active April 29, 2024 06:08
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrintrepide/b3009f5d0f08d437ebbb4c17cbf36e18 to your computer and use it in GitHub Desktop.
Save mrintrepide/b3009f5d0f08d437ebbb4c17cbf36e18 to your computer and use it in GitHub Desktop.
AV1 quick encode with SVT-AV1

SVT-AV1 is the fastest multithreaded AV1 encoder
You can download up to date BtbN ffmpeg build with latest STV-AV1 code.

Aom-av1 is the official av1 decoder/encoder but it's the slowest and lacks of a real massive multithreading.
Rav1e is a xiph encoder project. It's also very slow but you can use multithreading with tiles.
Dav1d is a veryfast AV1 VLC decoder project.

Svt-av1 is an heavy multithreading intel decoder and encoder. It produce good quality but bigger file size.
It can produce 8 and 10 bit video with CRF (default), CQP, VBR and CBR (test).
Two pass are also available with standalone SvtAv1EncApp but not in ffmpeg.

Like HEVC and VP9, 8 bit low bitrate video create banding. 10 bit is prefered. Today intel/amd/nvidia/qualcomm/mediatek hardware video decoder support hevc, vp9 and now av1 10 bit. It produce better dark/black anime scene in 10 bit and smaller file size.

Base ffmpeg

Default:
ffmpeg -i "Input.mkv" -c:v libsvtav1 -crf 35 -preset 6 -c:a libopus -b:a 128k -ac 2 -c:s copy Output.mkv

Optimal 8 bit:
ffmpeg -i "Input.mkv" -c:v libsvtav1 -crf 35 -preset 6 -svtav1-params tune=0 -g 240 -c:a libopus -b:a 128k -ac 2 -c:s copy Output.mkv

Optimal with 10 bit:
ffmpeg -i "Input.mkv" -pix_fmt yuv420p10le -c:v libsvtav1 -crf 35 -preset 6 -svtav1-params tune=0 -g 240 -c:a libopus -b:a 128k -ac 2 -c:s copy Output.mkv

-pix_fmt yuv420p10le convert input video to 10 bit format
-g 240 set gop size to 10s for 24 fps video

Speed

-preset set speed (0 to 13), 13 is for test and debug.
6 for medium, 4 for slow
Lower than 3 is extremly slow, higher than 9 are too destructive.

Quality

-crf use value 35 is good, but you can use 32-35 to produce small file

Custom svt-av1 parameters

-svtav1-params specify custom svt-av1 parameters to encoder, use like this tune=0:film-grain=8:fast-decode=0

tune 0 for Visual quality, 1 for PSNR optimisation

1 pass 10bit ffmpeg -hide_banner -loglevel warning -i 'Shingeki no Kyojin.mkv' -nostdin -strict -1 -pix_fmt yuv420p10le -f yuv4mpegpipe - | ./SvtAv1EncApp -i stdin --preset 1 -q 25 --irefresh-type 2 --keyint 240 -b out1.ivf on Ryzen 3900X with a 1:30 anime opening

Preset Size (Bytes) Bitrate (kbps) Speed (fps) Time (s) VMAF PSNR SSIM MS-SSIM
2 53211486 4673,26 0,489 4464,818 94,857494 46,150474 0,988063 0,987445
3 57802120 5076,43 2,474 882,744 94,811056 46,144799 0,988047 0,987443
4 58029459 5096,39 3,308 660,291 94,801464 46,143351 0,988045 0,987441
5 60697739 5330,73 4,509 484,381 94,738653 46,067592 0,987997 0,987381
6 63622920 5587,64 8,595 254,102 94,795592 46,020972 0,987972 0,987347
7 63828836 5605,72 8,924 244,735 94,783249 46,008985 0,987969 0,987342
8 65718542 5771,68 17,058 128,037 94,200566 45,815277 0,987914 0,987256

Preset 4 is a good value for quality and 6 for quality/speed.
Preset lower than 3 are very very slow

@masterflitzer
Copy link

masterflitzer commented Jun 17, 2023

instead of using ffmpeg's -g 240 parameter you can also use -svtav1-params tune=0:keyint=10s or --keyint 10s respectively (5s is also a good value i personally use)

this is more flexible as it is universal no matter what framerate your input has

docs: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Parameters.md#gop-size-and-type-options

@drizzt
Copy link

drizzt commented Jun 21, 2023

-crf use value 35 is good, but you can use 32-35 to produce small file
crf of 32 is BIGGER than 35.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment