Skip to content

Sequences

Joe Drago edited this page Nov 19, 2020 · 6 revisions

AVIF Sequences

Using ffmpeg

Note: Please read the "Other Settings" at the end for reminders on important other settings.

This is the base form:

ffmpeg -i src.mp4 -f yuv4mpegpipe -strict -1 - | avifenc --stdin --fps 30 dst.avif
  • -strict -1 allows for 10bpc and 12bpc YUV formats to be used with y4m/yuv4mpegpipe. If you're working entirely with 8bpc data, you can probably omit it.
  • Set --fps to match the source material, of course.

The dimensions, YUV format, and range should all be automatically detected and honored by avifenc, so any changes you want to make to those should happen with a video filter, such as:

ffmpeg -i src.mp4 -vf "scale=480:270, format=yuv444p10" -f yuv4mpegpipe -strict -1 - | avifenc --stdin --fps 30 dst.avif

This can also be done as a two-step process if you want to avoid using a pipe. Simply remove -f yuv4mpegpipe and output to a .y4m file instead, and then supply that .y4m file instead of --stdin on the avifenc commandline:

ffmpeg -i src.mp4 -strict -1 tmp.y4m
avifenc --fps 30 tmp.y4m dst.avif

This can be helpful in debugging issues as well, as video players like VLC are happy to play .y4m files directly.

Setting CICP

Care should be taken to ensure that CICP (known in ffmpeg as color_primaries, color_trc, and colorspace) match in the resultant AVIF. This is currently not automatic, but using ffprobe to discover which values are used and matching them to proper CICP values will ultimately only require a minor tweak to the final commandline. For example, the most recent iPhone 12 Pro Max appears to store their HDR videos in BT.2020 HLG, with BT.2020 matrix coefficients. Running ffprobe on the MOV file produces a line similar to this:

Stream #0:0(und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 3840x2160, 39376 kb/s, 26.93 fps, 29.97 tbr, 600 tbn, 600 tbc (default)

The key part here for CICP is this piece: bt2020nc/bt2020/arib-std-b67. ffmpeg orders CICP differently than avifenc does (avifenc orders in nclx box order), so ffmpeg is saying here that CP=bt2020(9), TF=arib-std-b67(18) (HLG), and MC=bt2020nc(9). Adding onto our previous examples, that would look like this:

ffmpeg -i IMG.MOV -f yuv4mpegpipe -strict -1 - | avifenc --stdin --cicp 9/18/9 --fps 30 dst.avif

This would create a BT.2020 HLG AVIF (from the BT.2020 HLG .MOV) without doing any colorspace conversion.

Other Settings

  • Don't forget to actually configure the AV1 encoder on the avifenc commandline! Your final recipe should be making decisions about:
    • --jobs
    • --codec
    • --speed
    • --min
    • --max
  • Using -ss and -t on the ffmpeg commandline will allow you to trim a small part from the original file.
Clone this wiki locally