Skip to content

Latest commit

 

History

History
248 lines (178 loc) · 9.52 KB

DemuxingUHD.md

File metadata and controls

248 lines (178 loc) · 9.52 KB

How to Demux a UHD Blu-ray Disk

Setting Up DGDemux

Installation

  1. Download DGDemux:

  2. Install dovi_tool:

    • Download dovi_tool from its GitHub repository.
    • Extract and ensure the executable is in your system path.
    • Copy the updated dovi_tool executable into the DGDemux directory to replace the included version.

Adding to System Path

  • Add the DGDemux directory to your system path to make it accessible from any command prompt location.
  • Search online for instructions on how to add directories to the system path for your operating system.

Demuxing UHD Blu-rays

Step 1: Analyze the Disc Structure with DGDemux

Before demuxing specific streams, use the -d option to analyze the full disc structure and gather playlist information. This is essential for identifying the correct playlist.

  1. Command to analyze the disc structure:

    dgdemux -d "<FullPathToDecryptedDisc>"
    

    Example:

    dgdemux -d "D:\discs\MovieTitle"
    

    This command will display the list of playlists available on the disc, along with the associated chapter information for each.

  2. Interpret the output: The output will list all playlists and the number of chapters each contains, like this:

    PlayLists:
        00800.mpls 02:45:49 [18 chapters]
        00816.mpls 00:12:59 [2 chapters]
        00810.mpls 00:11:41 [2 chapters]
    

    From this list, you can identify the playlist you want to demux. Typically, the main feature will be the playlist with the longest duration and the most chapters.

Step 2: Demux Using DGDemux

Once you have the playlist identified, you can now use the -i option to specify the playlist and start the demuxing process.

  1. Basic Command: To demux all streams (audio, video, subtitles, chapters) from the selected playlist:

    dgdemux -i "<FullPathToDecryptedDisc>\PLAYLIST\<PlaylistNumber>.mpls" -o "<OutputFolderPath>\<OutputFilePrefix>"
    

    Example:

    dgdemux -i "D:\discs\MovieTitle\BDMV\PLAYLIST\00001.mpls" -o "D:\output\MovieTitle"
    
  2. Demux Specific Streams: If you want to extract only the video and audio tracks, use the -demux option to specify the PIDs:

    dgdemux -i "<FullPathToDecryptedDisc>\PLAYLIST\<PlaylistNumber>.mpls" -o "<OutputFolderPath>\<OutputFilePrefix>" -demux <PID1>,<PID2>
    

    Example (for audio PID 4352 and video PID 4113):

    dgdemux -i "D:\discs\MovieTitle\BDMV\PLAYLIST\00001.mpls" -o "D:\output\MovieTitle" -demux 4113,4352
    
  3. For Dolby Vision UHD Blu-rays: Use the -mergedv or -mergedv81 options to create merged streams with Dolby Vision metadata:

    • Base + Enhancement Layer Merge:
      DGDemux -i "<FullPathToDecryptedDisc>\PLAYLIST\<PlaylistNumber>.mpls" -o "<OutputFolderPath>\<OutputFilePrefix>" -mergedv
      

Verifying Dolby Vision UHD Blu-ray Mastering

The purpose of this section is to ensure that the UHD Blu-ray disc is mastered correctly. A properly mastered disc will have matching RPU and scene-cut data when the Metadata Enhancement Layer (MEL) is merged with the Base Layer (BL) compared to the untouched EL.

Step 1: Extract the Enhancement Layer (EL) RPU

Use dovi_tool to extract the Enhancement Layer (EL) and generate the RPU:

dovi_tool extract-rpu --input EL.hevc --output RPU_EL.bin

Important: The EL.hevc file might not actually be named EL.hevc and needs to be identified from the files created during the demuxing step. Typically, the EL file is the second .hevc file generated by DGDemux and is significantly smaller in size than the Base Layer (BL) .hevc file. Verify this by checking the file sizes in the output directory.

If you're unsure, compare the sizes of the .hevc files:

  • The larger file corresponds to the Base Layer (BL).
  • The smaller file corresponds to the Enhancement Layer (EL).

Once identified, substitute the correct filename for EL.hevc in the above command.

Step 2: Compare EL RPU Data with the BL and EL Merge RPU

  • Extract the RPU from the merged BL and EL file created by DGDemux:
dovi_tool extract-rpu --input merged_dovi.hevc --output RPU_MERGED.bin

The merged_dovi.hevc is created by DGDemux when selecting the -mergedv option.

  • Compare the original EL data RPU with the merged BL and EL RPU:
diff RPU_EL.bin RPU_MERGED.bin

Note If you do not have diff avilable you can install git for windows Once installed add C:\Program Files\Git\usr\bin\ to your PATH, as it already ships with a diff executable and installs it in that folder.

If the RPU files match, the disc is mastered correctly, and the RPU can be injected into the Base Layer (BL) during the remuxing process.

If discrepancies are detected:

  • Revisit the extraction or merging process to ensure no errors occurred.
  • If issues persist, the disc may be poorly mastered. Consider obtaining a corrected release from another region or a replacement disc.

With MEL, converting the RPU from the EL to Profile 8 can resolve some issues caused by incorrect Profile 7 RPUs. Use the following command to create the Profile 8 RPU:

DGDemux -i "<FullPathToDecryptedDisc>\PLAYLIST<PlaylistNumber>.mpls" -o "<OutputFolderPath><OutputFilePrefix>" -mergedv81

Verifying and Fixing the Crop/Active Area

Before proceeding to fix the crop, it's important to first verify if there is an issue with the crop and active area of the video. If discrepancies are found, you can then make the necessary adjustments to ensure the video displays correctly without cutting off parts of the image or introducing black bars.

  1. Verify the Crop:

    • Use the following command to inspect the active area offsets in the RPU:
    dovi_tool info -i RPU.bin -f 1
    

    Look at the active area offsets, which include:

    • active_area_left_offset
    • active_area_right_offset
    • active_area_top_offset
    • active_area_bottom_offset

    These values define the portion of the video that will be displayed. If the crop is incorrect, you might notice parts of the image being cut off or unwanted black bars appearing.

  2. Check Consistency Across Multiple Frames/Scenes: In general, the crop should remain consistent across all frames. However, it’s important to note that the crop can change per frame or scene, especially in content with dynamic cropping (e.g., IMAX scenes or content with different aspect ratios).

    • For typical content: The crop should remain the same throughout the video.
    • For content with variable aspect ratios (e.g., IMAX): The crop may change between scenes. In this case, you should check:
      • A normal scene (standard aspect ratio).
      • An IMAX scene (or any other scene with a different aspect ratio), as the crop may adjust to fit the wider image.
  3. Fix the Crop (if needed): If you identify issues with the crop (e.g., black bars or improper framing), use the dovi_tool editor to modify the active area offsets. Here’s how to fix the crop:

    • Download Example Configs:
      Pre-existing examples for editing the active area are available in the dovi_tool editor assets. You can find the examples here:

    • Edit the RPU:
      Use the dovi_tool editor with a JSON config that defines the new active area values. For example, to adjust the crop for the first 40 frames, use the following JSON:

      {
        "mode": 2,
        "active_area": {
          "crop": true,
          "presets": [
            {
              "id": 0,
              "left": 0,
              "right": 0,
              "top": 276,
              "bottom": 276
            }
          ],
          "edits": {
            "0-40": 0
          }
        }
      }

      Command:

      dovi_tool editor -i RPU.bin -j active_area_fix.json -o RPU_fixed.bin
      

      If you want to apply the fix to all frames, use this JSON:

      {
        "mode": 0,
        "active_area": {
          "presets": [
            {
              "id": 0,
              "left": 0,
              "right": 0,
              "top": 276,
              "bottom": 276
            }
          ],
          "edits": {
            "all": 0
          }
        }
      }

      Command:

      dovi_tool editor -i RPU.bin -j active_area_fix_all.json -o RPU_fixed.bin
      
  4. Inject the Updated RPU into the Merged File:
    Since the Base Layer (BL) and Enhanced Layer (EL) were already merged into one file (i.e., merged_dovi.hevc), which extracted the RPU from it, you do not need to mux the layers again. Instead, you can directly inject the modified RPU into the merged file.

    Use the following command to inject the modified RPU into the merged file:

    dovi_tool inject-rpu -i merged_dovi.hevc --rpu-in RPU_fixed.bin -o merged_with_RPU.hevc
    
    • merged_dovi.hevc: The already merged file that contains both the Base Layer (BL) and Enhanced Layer (EL).
    • RPU_fixed.bin: The updated RPU with the correct crop and other adjustments.
    • merged_with_RPU.hevc: The final output file with the injected RPU.
  5. Verify the Final Stream:
    After injecting the RPU, use dovi_tool info to inspect the final stream and verify that the crop and other RPU details are correct:

    dovi_tool info -i merged_with_RPU.hevc