Encoding Dolby Vision with StaxRip - staxrip/staxrip GitHub Wiki

Dolby Vision is a proprietary HDR format, and thus only limited information is released to the public. Therefore, you need to be aware that dealing with Dolby Vision format using open source tools can be limited because of its property.

Dolby Vision has two major types of profiles: single-layer profiles and dual-layer profiles. Most popular single-layer profiles are 5(Dolby Vision only), 8.1(HDR10 compatible), 8.2(SDR compatible) and 8.4(HLG compatible). Profile 7 is a typical dual-layer profile that is used in Dolby Vision 4K UHD Blu-ray content. It is composed of a base layer (BL, usually UHD), and an enhancement layer (EL, FHD).

Currently all encoders, that support Dolby Vision RPU metadata, are supported.
Those are x265, NVEncC and QSVEncC.

Since v2.35.0 StaxRip is able to properly extract the metadata, alter it if needed and hand over the metadata to the encoder. The responsible options are called Extract HDR metadata, which can limit the extraction, RPU Conversion Mode to convert the metadata into another profile and Import VUI metadata which copies and sets all necessary encoder settings. You can find them in Options » Video and by default they are set to ensure the most compatible option.

Figure A1:

Results:


Cropping

By default everything is set up correctly to extract All metadata, convert it (via Mode 2) and read it out. When it comes to cropping, the settings in Images » Crop are also important. Auto Crop is by default set to Dolby Vision only, but the metadata is also considered when set to Always. That means, that a source file with Dolby Vision metadata will be cropped after opening by default. (see Figure B1)

Limitations

Since v2.35 StaxRip ensures, that you get proper results without distracting the encode. This means, that you cannot crop more than the metadata allows you to do. If you try to crop too far into the image, you get a decent warning by the Assistant, telling you which side if affected, that you cannot skip. To ensure the max crop is set, the Auto Crop feature is enhanced to take the given metadata into account. You just have to open the source file and everything else is being prepared by StaxRip - for all types of Dolby Vision videos.

No crop even when there is a letterbox...
However there might be use cases, where you want to alter the cropping, for example when the image seems to have continuous same letterboxes, but StaxRip does not let you crop it. As it turned out, some videos have uncropped intros and outros, that use metadata as well, and StaxRip will (of course) protect those. So in order to solve the issue, you have to ignore these scenes, meaning you literally destroy the image or visual experience for that scene. If it's even visible depends on the scene itself and the metadata - maybe it's just a black screen. There are the following options to solve the issue:

Automatic:

This is the default setting. The Automatic takes the first/last 1000 frames into consideration. If there is an edit at the beginning/end, that is fullscreen and it is not used somewhere else that at the beginning/end, then they will be ignored.

Manual Threshold:

So in order to ignore the first and/or last seconds, you can set up a threshold in frames. This is what Dolby Vision AutoCrop Threshold is for (see Figure B1). StaxRip will ignore all presets before/after the given threshold when it comes to cropping. To not harm the outcome unintentionally, the feature is disabled by default, meaning the values are set to 0, but you can adjust them depending on your needs and/or source files. Typical values would be around 100-500 frames for both start and end. They can also be adjusted after opening the video file, the crop will then be adjusted automatically, regardless what was set before.
You may want to check out Manual Alteration, especially (Data D1), to know how to read out the exact scene change in case you want/need it.

Manual Alteration - for advanced users:

When the extraction of Dolby Vision metadata is enabled (see Figure A1) StaxRip extracts the RPU file and exports the Level5 data out of it, all using dovi_tool. Usually this file can be found in the Temp folder and it's name is HDRDVmetadata_L5.json. This file includes the "scenes", connected by id and separated in 2 blocks: presets and edits. To manually alter the data to get rid of the blocking scene(s), that StaxRip protects, you have to identify the one(s) that is/are causing it and verify, that it is not important for the video experience. So the relevant scenes are usually at the beginning and/or the end. Identify them and replace the values with high ones, such as 9999, but at least with the lowest one that are important to protect. In Data 2 I decided to copy the values from the main scene. After that, you have to save the file and open the source file again in StaxRip - opening the saved project will not work! Because the metadata files are not overwritten by StaxRip, this time it won't complain anymore and, depending on your settings, auto crop the video based on the metadata.
⚠️ Be careful, otherwise you might destroy the encode!

Data 1: Typical Level5 data of a video with uncropped metadata at the beginning
{
  "crop": true,
  "presets": [
    {
      "id": 0,
      "left": 0,
      "right": 0,
      "top": 0,
      "bottom": 0
    },
    {
      "id": 1,
      "left": 0,
      "right": 0,
      "top": 276,
      "bottom": 276
    }
  ],
  "edits": {
    "0-311": 0,
    "312-186545": 1
  }
}
Data 2: Altered Level5 data to ignore the intro scene and crop the video
{
  "crop": true,
  "presets": [
    {
      "id": 0,
      "left": 0,
      "right": 0,
      "top": 276,
      "bottom": 276
    },
    {
      "id": 1,
      "left": 0,
      "right": 0,
      "top": 276,
      "bottom": 276
    }
  ],
  "edits": {
    "0-311": 0,
    "312-186545": 1
  }
}

Figure B1:


Side notes

  1. LSMASHVideoSource (20210423 HolyWu) seems to have an issue with opening the Dolby Vision hevc streams (both Profile 5 and Profile 8.1): the frame rate (or playback duration) is totally wrong. It seems that the problem is due to L-SMASH itself (upstream issue). See here for detail. Therefore, use another source filter like FFVideoSource or LWLibavVideoSource.

  2. Do not enable chunk encoding. Since the dynamic metadata (RPU) is dependent on scenes/frames, splitting only frames by enabling chunk encoding is definitely not going to work well.

  3. Profile 5 is playable on only Dolby Vision enabled devices. So it cannot be played properly on open source players like mpv, mpc, etc. The tonemapping is really weird if the Dolby Vision dynamic metadata is not properly parsed and applied by the player. This is true even if you force-put HDR10-like metadata (SMPTE 2086) in the video stream by re-encoding or if you tonemap the Profile 5 source video down to SDR following the standard methods.


External Informative Links

⚠️ **GitHub.com Fallback** ⚠️