HDR imagery in AVIF files

I thought I should explain the process I’m using to create the HDR avif files I’m using on the ACES ODT Candidates page:


I’m using the avifenc command line tool, which is part of the libavif bunde of tools from here:

I’m on a Mac, and just installed it via: brew install libavif

To make the process of generating the images a bit simpler for myself, I’ve made a very basic nuke wrapper for the tool, which you can see if you open the nukescript I’m using to generate the images here:

The Write nodes are all dumping out 16nit png files, preencoded as Rec.2020 PQ, and there are a couple of custom user knobs added to each node.

One for setting the path where I want to write the final avif files (which is just based off the name of the png files, with a new destination and extension)
And 3 for setting the CICP Coding-independent code points - Wikipedia metadata flags.

Then, under the python tab, there is a simple “after each frame” callback, that runs the python code below after each frame:

import sys
from subprocess import Popen

node = nuke.thisNode()
#node = nuke.selectedNode()
sourcePath = node.knob('file').evaluate()
destinationPath  = node.knob('destinationPath').evaluate()
cicp_P = str(int(node.knob('cicp_P').value()))
cicp_T = str(int(node.knob('cicp_T').value()))
cicp_M = str(int(node.knob('cicp_M').value()))
cicp_string = '/'.join([cicp_P,cicp_T,cicp_M])

commandString = '/usr/local/bin/avifenc  --cicp %s  \"%s\"  \"%s\" ; rm \"%s\"' % (cicp_string,sourcePath,destinationPath,sourcePath)

proc = Popen([commandString], shell=True,
             stdin=None, stdout=None, stderr=None, close_fds=True)

In short, it just grabs the input png path, the output avif path, the cicp flags, forms an avifenc command, runs it, then deletes the orginal png frame.

Something like:
/usr/local/bin/avifenc --cicp 9 16 9 original.png output.avif
rm original.png

Just Render, and the avif files are ready to go.

If anyone is interested in the code used to generate the webpages themselves, the code is all in here:


Hi Alex,

thanks for the detailed explanation. I encoded my first AVIF file. :nerd_face:

Just a quick question, how can I change the amount of the compression converting from png to avif?
I encoded the A fully red star on a fully cyan background... in ACES, but for now “only” in Display P3.

The image works when I drop it into Chrome on the XDR MBP, but the compression artifacts are huge and the resulting file has only 4KB.

The -l will output lossless.
There are other flags for variable compression, but I haven’t got a good handle on them yet.

1 Like