To convert an HDR PNG that's exported with HLG transfer function in Rec. 2020 color space, do:
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a tune=ssim \
-a color:enable-chroma-deltaq=1 -a color:enable-qm=1 -d 12 --cicp 9/18/9 IMG_0186.png IMG_0186.avif
For HDR with PQ transfer function in Rec. 2020 color space, do:
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a tune=ssim \
-a color:enable-chroma-deltaq=1 -a color:enable-qm=1 -d 12 --cicp 9/16/9 IMG_0186.png IMG_0186.avif
For the default SDR image (sRGB with BT.601 coefficients), simply do:
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a color:deltaq-mode=3 -a tune=ssim \
-a color:enable-chroma-deltaq=1 -a color:enable-qm=1 --cicp 1/13/6 IMG_0186.png IMG_0186.avif
For the same with BT.709 coefficients, do:
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a color:deltaq-mode=3 -a tune=ssim \
-a color:enable-chroma-deltaq=1 -a color:enable-qm=1 --cicp 1/13/1 IMG_0186.png IMG_0186.avif
Notes:
- Setting
deltaq-modeto5(HDR) doesn't seem to make a difference at all,3produces slightly smaller files for SDR images. - If
--cicpis ignored and the source image doesn't specify any profile,2/2/6is used where2means unspecified. This is okay for sRGB.
# source https://github-wiki-see.page/m/wswartzendruber/hlg-tools
hlg-tools/pq2hlg -r 210 -m 4000 pq2hlg.cube
# color-map using the above LUT
ffmpeg -i HDR_sample_pq.png -vf format=rgb48le,lut3d=pq2hlg.cube -color_primaries bt2020 -color_trc arib-std-b67 -colorspace bt2020nc HDR_sample_hlg.png
# the above PNG will have bad metadata (ffmpeg issue?), so viewer apps will render it badly by default
# convert to avif with the correct transfer function (HLG: 18)
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a tune=ssim -a color:enable-chroma-deltaq=1 -a color:enable-qm=1 -d 12 --cicp 9/18/9 HDR_sample_hlg.png HDR_sample_hlg.avif
# copy EXIF tags from the original DNG file
exiftool -TagsFromFile IMG_0025.DNG "-all:all>all:all" HDR_sample_hlg.avif
Opening the AVIF file converted from the direct PNG (PQ or HLG) export from Affinity Photo 2 in iPhone is slower than doing it after these steps. The only explanation I could come up with is the removal of alpha channel perhaps... 🤔
ffmpeg -i .\IMG_0025-0027_pq.png -vf format=rgb48le -color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc IMG_0025-0027_pq2.png
avifenc -s 4 -j 4 --min 1 --max 56 -a end-usage=q -a cq-level=18 -a tune=ssim -a color:enable-chroma-deltaq=1 -a color:enable-qm=1 -d 12 --cicp 9/16/9 IMG_0025-0027_pq2.png IMG_0025-0027_pq2.avif
exiftool -TagsFromFile IMG_0025.DNG "-all:all>all:all" IMG_0025-0027_pq2.avif
Sources:
- https://github.com/AOMediaCodec/libavif/wiki/CICP
- https://en.wikipedia.org/wiki/Coding-independent_code_points
- https://old.reddit.com/r/AV1/comments/o7s8hk/high_quality_encoding_of_avif_images_using/
- https://wiki.x266.mov/docs/encoders/aomenc#avif-encoding
- (av1 video) https://www.reddit.com/r/AV1/comments/t59j32/encoder_tuning_part_4_a_2nd_generation_guide_to/
- (av1 video) https://gist.github.com/nico-lab/a6508f283a77696e79a131e07abd86b9
- https://github-wiki-see.page/m/wswartzendruber/hlg-tools/wiki/pq2hlg
- https://trac.ffmpeg.org/wiki/colorspace
- https://wiki.x266.mov/docs/colorimetry/transfer#14-bt2020-10-bit