Skip to content

Av1 encoding


  • (JPEG DCT)[]
  • (Huffman trees)[]
  • (Everything you need to know about JPEG)[]
  • (Why does 10bit save bandwidth?)[]

My reply to a post on Reddit

This is an interesting write up (and the same applies to your links /u/Darkjacky, but I will keep this to a single reply), but there is no real explanation as to why higher bit color depth allows for lower bitrates while achieving the same perceived quality, only an anecdote. That being said, these resources did give me the vocabulary to do some meaningful research on my own!

It came down to me more deeply understanding the DCT (or similar) portion of the compression process which I will represent briefly as: 1) Represent the YUV data as cosine coefficients 2) Quantize the output 3) Compress the quantized output using Hoffman Coding

Now due to the nature of the quantization process, at step 3 we are left with a large array consisting mostly of zeros which compresses very efficiently with Hoffman Coding; in short, we are assigning a small code to symbols with larger frequencies and larger codes to those with lower frequencies.

I kept seeing the phrase "higher bit depth reduces error" but what I couldn't figure out was where and how that is helpful.

To my understanding, by increasing the color bit depth we are able to reduce the error and subsequent banding[1] in the encoding and decoding of steps 1 & 2 (of the DCT process). In the end, the data is still being represented as quantized cosine coefficients, and we are still left with the same compressible array in step 3. The difference is that now we are able to quantize more heavily, reducing the amount of unique coefficients, while achieving the same perceptive quality.

Please let me know if any of this is incorrect or not grasping all the benefits of higher bit depth.

[1] I will admit I am still at a shallow understanding of the sentence "by increasing the color bit depth we are able to reduce the error and subsequent banding". I would love a truly tangible example of this effect.

AV1 encode

There is not much official documentation regarding the efficacy or results of the -cpu-used and the crf flags. Someone on reddit did some testing which leads me to believe -cpu-used settings 2-4 are the only practical settings to use.

As we can see in the graph below, the CRF value will also significantly increase encode time when below 25. A CRF value of 23 should produce a nearly identical quality to the original, but is incredibly slow. A value of 35 gets very close to halving that time.


At the same time, the user BlueSwordM who has written many posts about AV1 encoding has suggested some settings and significantly a crf setting of 18 for high fidelity encodes.

AV1 video encode with ffmpeg

time ffmpeg -i sample-1min.mkv \
                -c copy \
                -c:v libaom-av1 -cpu-used 4 -threads 4 -crf 30 \
                -arnr-strength 0 -aq-mode 1 -denoise-noise-level 20 -lag-in-frames 48 \
                -g 240 -keyint_min 12 -pix_fmt yuv420p10le \
                -aom-params sb-size=64:enable-qm=1:enable-dnl-denoising=0:deltaq-mode=0 \
                sample-libaom-cpu4-threads4-crf30-dn20-10bit.mkv > sample-libaom-cpu4-threads4-crf30-dn20-10bit.log
time ffmpeg -i sample-1min.mkv \
                -c copy \
                -c:v libsvtav1 -preset 3 -crf 23 -g 240 -pix_fmt yuv420p10le \
                -svtav1-params tune=0:film-grain=18:film-grain-denoise=0:lp=32 \
                sample-svt-p3-crf30-10bit.mkv > "ffmpeg.log"

Single shot remux

ffmpeg -i Future.Boy.Conan.S01.1080p.BluRay.x264.ja/Future.Boy.Conan.s01e01.ja.mkv \
-i Future.Boy.Conan.S01.1080p.BluRay.x264.en/Future.Boy.Conan.s01e01.en.mkv \
-max_interleave_delta 0 \
-muxdelay 0 \
-map 0 \
-map 1:a \
-map 1:s:0 \
-c copy \
-c:v libaom-av1 \
-crf 23 \
-row-mt 1 \
-tiles 2x2 \
-cpu-used 3 \

Note: during this process I discovered that pulling out subtitles can sometimes lose timing. It is better to mux subtitles in one shot to prevent this.

Install ffmpeg with av1 enabled on mac

AS of now (06/01/23) ffmpeg does not compile their binaries with svtav1 enabled.

brew tap georgemcarlson/svt-av1
brew install georgemcarlson/svt-av1/svt-av1
brew tap georgemcarlson/ffmpeg
brew install georgemcarlson/ffmpeg/ffmpeg