Transcode Multi-Channel EXR with FFmpeg

This article provides a direct guide on how to identify, select, and extract specific layers from multi-channel OpenEXR (EXR) image sequences during transcoding using FFmpeg. You will learn how to inspect EXR metadata to locate available channels and use target FFmpeg commands to transcode these layers into standard video or image formats.

Step 1: Identify the Available EXR Layers

Before transcoding, you must identify the exact names of the layers embedded inside your EXR file (such as Beauty, Depth, Specular, or Normals). You can use ffprobe to inspect the metadata and list the available channels.

Run the following command in your terminal:

ffprobe -v error -show_streams input.exr

Look for the stream metadata or tag outputs. FFmpeg will typically list the detected channel names (e.g., R, G, B, A, or custom layer prefixes like depth.Z).

Step 2: Extract a Specific Layer Using the -layer Option

FFmpeg’s openexr decoder features a private option called -layer that allows you to specify which layer you want to decode. Because this is an input option, you must place the -layer flag before the input file (-i) in your command.

To transcode a specific layer (for example, a layer named Diffuse) from an EXR sequence into an MP4 video, use the following command:

ffmpeg -layer "Diffuse" -i input_%04d.exr output.mp4

For a single image conversion:

ffmpeg -layer "Diffuse" -i input.exr output.png

If the specified layer name is not found, FFmpeg will fail and output a list of the actual layer names available in the file, which serves as an alternative way to discover channel names.

Step 3: Transcoding Multiple Layers Simultaneously

If you need to extract and transcode multiple layers into separate files in a single run, you can define the input multiple times, specifying a different -layer option before each input instance.

The following command extracts both the Beauty layer and the Depth layer simultaneously into two separate output files:

ffmpeg -layer "Beauty" -i input_%04d.exr -layer "Depth" -i input_%04d.exr -map 0:v beauty_output.mp4 -map 1:v depth_output.mp4

Step 4: Handling Color Spaces (Linear to Gamma)

EXR files store image data in linear color space. When transcoding to formats like PNG or MP4 for web viewing, the output may look dark or washed out if you do not apply a gamma correction.

To convert the linear EXR color space to sRGB (gamma 2.2) during transcoding, apply the lutrgb or format and colorspace filters:

ffmpeg -layer "Beauty" -i input_%04d.exr -vf "lutrgb=r=gval(val*2.2):g=gval(val*2.2):b=gval(val*2.2),format=yuv420p" output.mp4