Dolby Vision Metadata RPU Editing Guide

Dolby Vision Metadata RPU Editing Guide

Professional Instructional Document

Introduction

In almost all cases, the source Dolby Vision metadata RPU (Reference Processing Unit) needs to be edited for use in an encode or another video. This guide will walk you through the process using dovi_tool and, for most examples, ffmpeg.

Suggested RPU Editing Workflow

Extract the RPU with mode 0

ffmpeg -i source.mkv -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool -m 0 extract-rpu -

It's possible this step can fail with invalid files (e.g., from Apple). Remove mode 0 if you know what you're doing.

Sync and Compare Video Files

Load both video files in a frame server (VapourSynth/AVISynth). Figure out the sync difference (start offset, more frames in one). Usually, files from the same service are already in sync.

Sync Differences (Click to Expand)

If there are sync differences, adjust them in your frame server script.

Check HDR Grade

Determine if the HDR grade is the same. Typically, files from the same service have the same HDR grade.

Processing Dolby Vision (Click to Expand)

Refer to the section on processing Dolby Vision for more details.

Determine the Active Area (Letterbox Bars)

Active Area Detection (Click to Expand)

Identify and account for letterbox bars in your video. Adjustments may be necessary to ensure proper cropping and aspect ratio preservation.

Add the Conversion Mode

For profile 7 (UHD Blu-ray) sourced encodes, use mode 2. For profile 5 source metadata to be used with HDR10 video, use mode 3.

In the case of encoding profile 7 FEL, it is recommended to always use "remove_mapping": true when converting to profile 8.1. This prevents extra processing that may alter the image. Note that in dovi_tool versions 2.0.0 and above, the "remove_mapping" step is not required if the source RPU is profile 7 FEL.

Example JSON Configuration

{
    "mode": 3
}

All of the editor steps can be combined into a single JSON file.

Final JSON Example (Click to Expand)

{
    "mode": 3,
    "remove_mapping": true,
    "active_area": {
        "top": 140,
        "bottom": 140
    },
    "hdr10_metadata": {
        "maxcll": 630.04,
        "maxfall": 5.83,
        "max_luminance": 1000
    }
}

Run the Editor Using JSON

dovi_tool editor RPU.bin -j edits.json

After running the editor, the new RPU is saved as RPU_modified.bin or whatever output name you choose.

Encoding: Adjust the HDR10 Metadata

Adjusting HDR10 Metadata (Click to Expand)

The RPU metadata is accurate for the Dolby Vision presentation, including situations where the FEL impacts final brightness. Use dovi_tool info -s RPU.bin to obtain the RPU info:

RPU mastering display: 0.0001/1000 nits
RPU content light level (L1): MaxCLL: 630.04 nits, MaxFALL: 5.83 nits
L6 metadata: Mastering display: 0.0001/1000 nits. MaxCLL: 1712 nits, MaxFALL: 175 nits

Most of the time, if the L1 MaxCLL is not 10,000 nits, it should be fine to use as is. This metadata can be used with x265.

Processing Dolby Vision in AviSynth/VapourSynth

This section covers the tools and methods needed for processing Dolby Vision content using AviSynth or VapourSynth.

Required Tools

  • AviSynth: avslibplacebo
  • VapourSynth: vs-placebo
  • Linux:
    • libplacebo 4.192.0+
    • ffms2 git
    • awsmfunc and vsutil
  • Windows:
    • ffms2 from git (or saiclabs' pack)
    • awsmfunc and vsutil

Preferred Tools for FEL Encoding

  • (Preferred) AVS-MapNLQ for FEL encoding: AviSynthPlus-MapNLQ
  • (Old) DoViBaker for FEL encoding: Available in saiclabs' pack

The fork is important to have outYUV=true. Otherwise, extra steps need to be taken, and they are not covered in this guide.

Profile 7 FEL Encoding

Profile 7 FEL Encoding Details (Click to Expand)

VapourSynth

Steps for VapourSynth

  1. Demux the enhancement layer (EL) from the source:
    ffmpeg -i source.mkv -c:v copy -vbsf hevc_mp4toannexb -f hevc - | dovi_tool demux --el-only -
  2. Extract the RPU from the EL:
    dovi_tool -m 0 extract-rpu EL.hevc
  3. Mux the EL to MKV.
  4. Edit the RPU as per the first post.

Example VapourSynth Script

import awsmfunc as awf

src = core.ffms2.Source("source.mkv")
el = core.ffms2.Source("EL.mkv")
src = awf.MapDolbyVision(src, el)

src = src.std.Crop(top=276, bottom=276)
# ... the rest of your filtering
src = vsutil.depth(src, 10, dither_type="error_diffusion")

AviSynth Using MapNLQ (Preferred Method)

FFVideoSource("BL.mkv")
z_ConvertFormat(bit_depth=16)
libplacebo_Tonemap(src_csp=3, dst_csp=1)
bl=z_ConvertFormat(pixel_type="yuv420p16", chromaloc_op="top_left=>top_left", resample_filter="spline36")

el=FFVideoSource("EL.mkv")

MapNLQ(bl, el)
#MapNLQ(bl, el, rpu)
z_ConvertFormat(pixel_type="yuv420p10", dither_type="error_diffusion")
Prefetch(2)

AviSynth Using DoViBaker

FFVideoSource("BL.mkv")
bl=ConvertBits(16)
FFVideoSource("EL.mkv")
el=ConvertBits(16)
DoviBaker(bl, el, "el_RPU.bin", outYUV=true)
z_ConvertFormat(pixel_type="yuv420p10", dither_type="error_diffusion")

If you process the FEL as above, you need to add "remove_mapping": true to the editor JSON. When the source is FEL, "remove_mapping": true should always be used to avoid issues with mode 2. New: In dovi_tool versions 2.0.0 and above, the "remove_mapping" step is not required if the source RPU is profile 7 FEL.

Profile 5 to HDR10

Profile 5 to HDR10 Conversion (Click to Expand)

VapourSynth Script for Profile 5 Release

import vsutil

clip = core.ffms2.Source("the.bad.guys.2022.dv.2160p.web.h265-slot.mkv")

clip = core.std.SetFrameProp(clip, prop="_ColorRange", intval=0)

clip = vsutil.depth(clip, 16)
clip = core.placebo.Tonemap(clip, src_csp=3, dst_csp=1)

clip = core.std.SetFrameProps(clip, _Primaries=9, _Matrix=9, _Transfer=16)
clip = clip.resize.Spline36(range_in_s="full", range_s="limited")

clip = vsutil.depth(clip, 10, dither_type="error_diffusion")

AviSynth Script for Profile 5 Release

FFVideoSource("the.bad.guys.2022.dv.2160p.web.h265-slot.mkv")
propSet("_ColorRange", 0)
ConvertBits(16)
libplacebo_Tonemap(src_csp=3, dst_csp=1)
fmtc_bitdepth(10, fulls=true, fulld=false, dmode=6)

Remuxing Dolby Vision or Making a "Hybrid" Release

Hybrid Release Details (Click to Expand)

In most cases, the desired video is HDR10 with profile 8.1 metadata.

Steps for Hybrid Release

  1. Edit the RPU as per the first post. Use mode 3 for converting when the source is profile 5.
  2. Ensure the HDR grade is the same between both profile 5 and HDR10 video.
  3. Demux HDR10 video using ffmpeg or mkvextract.
  4. Inject the RPU:
    dovi_tool inject-rpu HDR10_video.hevc --rpu-in RPU_modified.bin
  5. Mux injected_output.hevc as usual.

You should obtain a file with this MediaInfo:

Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2086, HDR10 compatible

Additional Resources and References

© 2024 Dolby Vision Metadata RPU Editing Guide | All Rights Reserved

Comments

Popular posts from this blog