scripts:ffmpeg:av1_hdr_sdr

This is an old revision of the document!


AV1 encoding with HDR to SDR tonemapping and 5.1 to stereo downmixing

If you want real surround audio, use Sofa. But that only sounds good with headphones, and I want a 2.0 speaker mix.

ffmpeg -i legit_file.mkv -c:v libsvtav1 -crf 34 -preset 2 -threads 4 -g 240 -svtav1-params tune=0:film-grain=10:mbr=3000k -vf 'zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p,scale=if(gte(iw\,ih)\,min(1920\,iw)\,-2):if(lt(iw\,ih)\,min(1920\,ih)\,-2):flags=lanczos+full_chroma_inp+full_chroma_int' -c:a libopus -vbr on -b:a:0 128k -b:a:1 32k -compression_level 10 -application audio -af “pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.707*c5+0.5*c3” -colorspace:v “bt709” -color_primaries:v “bt709” -color_trc:v “bt709” -color_range:v “tv” -map 0:0 -map 0:1 -map 0:2 -map 0:s -c:s copy -y “legit_transcode_av1.mkv”

This is optimized to squash down the files. A movie should be under 2 GB but with much better results than h264 or h265.
This uses hable tonemapping. See https://ffmpeg.org/ffmpeg-filters.html#tonemap-1 for your options, I kinda preferred the slightly brighter hable image.
It's not as good as MPV's tonemapping is, but MPV is a player, not a transcode…
This uses a dumb audio downmix, but has slightly more center for benefit of vocals.
I would map primary audio opus at 128 (you won't hear the difference in a movie), and any vocal special things like director commentary down to 32.
NOTE: This drops to 8 bit color. YOU WILL SEE BANDING WITH 8 BIT. Choose 10 bit, or even FULL RANGE 8 bit instead of limited.
Why did I do it this way? At least some HW accelerated players can handle 8 bit but struggle with 10 (Rockchip) but note that they will NOT do the film grain synthesis.

  • scripts/ffmpeg/av1_hdr_sdr.1740476315.txt
  • Last modified: 2025-02-25 09:38
  • by Tony