1

I try to encode this 4k VP9 HDR10 vídeo: https://www.youtube.com/watch?v=kgppJX0G--E using this command line:

ffmpeg \
  -vsync 0 \
  -hwaccel cuda \
  -hwaccel_output_format cuda \
  -c:v vp9_cuvid \
  -crop 276x276x0x0 \
  -i "(PS5) THE PACIFIC WAR 1943 | Realistic Immersive ULTRA Graphics Gameplay [4K 60FPS HDR] Call of Duty [kgppJX0G--E].webm" \
  -c:v hevc_nvenc \
  -preset slow \
  -rc vbr \
  -rc-lookahead 20 \
  -b:v 28M \
  -bufsize 5M \
  -maxrate 28M \
  -g 250 \
  -an \
  -sn \
  output_video.hevc

FFMpeg works fine BUT doesn't save HDR10 in HEVC output video (with "hevc_cuvid" no problem). FFMpeg gives these errors:

Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
[vf#0:0 @ 0x557dd530b600] Error reinitializing filters!
[vf#0:0 @ 0x557dd530b600] Task finished with error code: -38 (Function not implemented)
[vf#0:0 @ 0x557dd530b600] Terminating thread with return code -38 (Function not implemented)
[vost#0:0/hevc_nvenc @ 0x557dd5313700] Could not open encoder before EOF
[vost#0:0/hevc_nvenc @ 0x557dd5313700] Task finished with error code: -22 (Invalid argument)
[vost#0:0/hevc_nvenc @ 0x557dd5313700] Terminating thread with return code -22 (Invalid argument)
[out#0/matroska @ 0x557dd52a7000] Nothing was written into output file, because at least one of its streams received no packets.

1 Answers1

2

For encoding HDR video with correct brightness and colors, we may add hevc_metadata Bitstream Filter as follows:

-bsf:v hevc_metadata=colour_primaries=9:transfer_characteristics=16:matrix_coefficients=9


A bitstream filter operates on the encoded stream data, and performs bitstream level modifications (hevc_metadata modifies metadata embedded in an HEVC stream).

The reason we have to modify the HEVC stream embedded metadata, is that the "color description" metadata is crucial for correctly playing HDR video (it term of brightness and colors), and FFmpeg doesn't automatically pass these properties from the input to the output.

For viewing these "color description" properties, we may use MediaInfo tool.

Color description properties of input video stream:

Color range                              : Limited
Color primaries                          : BT.2020
Transfer characteristics                 : PQ
Matrix coefficients                      : BT.2020 non-constant

Color description properties of output video stream: (without the bitstream filter):

Color range                              : Limited
Matrix coefficients                      : Identity

As we can see, only the "Color range" property is passed correctly from the input to the output.


Getting the correct numbers (9, 16 and 9) requires some effort...
The documentation says "Set the colour description in the stream (see H.265 section E.3.1 and tables E.3, E.4 and E.5)". We actually have to get the numbers from the tables in the H.265 standard documentation.

After adding the bitstream filter, the color description properties of the output are the same as of the input:

Color range                              : Limited
Color primaries                          : BT.2020
Transfer characteristics                 : PQ
Matrix coefficients                      : BT.2020 non-constant

Note:
The solution is unrelated to the error message: Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'

Rotem
  • 3,346