Convert EXR to Rec. 2020 HEVC with FFmpeg

This article provides a step-by-step guide on how to convert a high-dynamic-range (HDR) OpenEXR image sequence into a compressed Rec. 2020 HEVC (H.265) video using FFmpeg. You will learn the exact command-line parameters required to handle linear-to-HDR color space conversions, maintain 10-bit color depth, and embed the correct HDR metadata for seamless playback on modern HDR displays.

Prerequisites

To perform this conversion, your FFmpeg build must be compiled with: * --enable-libx265 (for HEVC encoding) * --enable-libzimg (for the zscale filter, which handles high-precision color space conversions)

The FFmpeg Command

To convert a linear Rec. 2020 EXR sequence to an HDR10 (Rec. 2020, PQ transfer function) HEVC video, use the following command:

ffmpeg -framerate 24 -i input_%04d.exr -vf "zscale=tin=linear:pin=bt2020:t=smpte2084:p=bt2020:r=limited,format=yuv420p10le" -c:v libx265 -crf 18 -x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1):max-cll=1000,400" output.mp4

Parameter Breakdown

1. Input Settings

2. Video Filter (-vf)

The zscale filter converts the linear high-bit-depth EXR data into the correct HDR10 format: * tin=linear: Tells FFmpeg the input transfer characteristics are Linear. * pin=bt2020: Identifies the input primaries as Rec. 2020. If your EXR files use ACES AP1 or Rec. 709 primaries, change this parameter accordingly (e.g., pin=bt709). * t=smpte2084: Converts the transfer curve to SMPTE ST 2084 (PQ curve, standard for HDR10). * p=bt2020: Sets the output color primaries to Rec. 2020. * r=limited: Standardizes the color range to limited (video range), which is required for standard HEVC distribution. * format=yuv420p10le: Outputs to 10-bit YUV 4:2:0, the standard pixel format for HDR10 compatibility.

3. Encoding and Metadata Settings