Long Story Short I have published this guide on Reddit
And the same guide is attached here too.
How to downscale from Proper 4k to 1080p, keeping DV and DA intact
How to downscale from Proper 4k to 1080p, keeping DV and DA intact
I have a rip of 2001 space odyssey from 4k Blu-ray, which contains the following metadata for Video
Video
ID : 1
ID in the original source medium : 4113 (0x1011)
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@High
HDR format : Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
Codec ID : V_MPEGH/ISO/HEVC
Duration : 2 h 28 min
Bit rate : 64.3 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(PixelFrame) :* 0.323
Stream size : 66.8 GiB (87%)
Language : English
Default : No
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : BT.2020
Mastering display luminance : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 992 cd/m2
Maximum Frame-Average Light Level : 282 cd/m2
Original source medium : Blu-ray
tldr: Steps to change just the resolution from 4k to 1080p while keeping the other parameters intact.
1. Extract the rpu with crop option
2. Encode video with the same crop offset as the original untouched rpu file
3. Inject the cropped rpu file with a new encoded cropped file.
4. Remux it all together
SOLUTION :
[Blu-ray Ripping & Reading Metadata]
Here’s the Solutions, a step by step guide on how to encode a 4k Blu-ray to 1080p and still retain the Dolby goodness.
- Rip the Blu-ray using MakeMKV, and verify the now created MKV file (herein after refer to as the “OG” file) contains the Dolby Vision or not by using the latest version of MediaInfo (open “OG” file in here and view it in either HTML or Text form), and look for the “HDR” info stating something like this [HDR format : Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible]
[Dolby Vision Extraction]
- Once verified that Dolby Metadata exists, we move to the next part. We have to now extract the Dolby Metadata from the “OG” file, I choose the simple way of using a GUI based application to extract the metadata but you will also require Dovi_Tool for further process, open and run HDRDV_Multi_Tool_GUI and select the “OG” file in the GUI and run to extract the RPU in two formats (as your use case changes, read the each authors wikis for more.)
a. Untouched Format / Converted Format without cropped option.
b. Untouched Format / Converted Format with cropped option.
c. Or you may also use the Dovi_Tool command like for example dovi_tool for more on this) and add an extra option of “crop” refer this command for moreffmpeg -i /path/to/input.mkv -c:v copy -bsf:v hevc_mp4toannexb -f hevc - | dovi_tool -m 2 -c extract-rpu - -o /path/to/RPU.bin
d. Now use the following command dovi_tool info -i /path/to/without_crop_rpu/file -f ‘enter frame number’
e. Look for the following part in the output"Level5": {"active_area_left_offset": 0,"active_area_right_offset": 0,"active_area_top_offset": 276,"active_area_bottom_offset": 276}"
f. The above Step5 is to identify the Level5 offset data this is where you will find numbers for cropping your “OG” file to “Encoded” file with cropping, so be mindful of the above steps.
[Encoding Phase]
- Now that you have extracted the RPU files of Dolby Metadata of “OG” file we now have to encode the “OG” file from 4k to 1080p using any of the following Staxrip_GUI or FastFlix_GUI (for on how to use these software its best to refer their wikis), once encoded to your liking the new file (herein after refer to as the “Encoded” file) will not have the Dolby metadata in it you can verify the same using the above given MediaInfo tool.
[Encoding Enhancements]
-
According to the dovi_tool developer the RPU would need to be recalculated for it to be accurate at the new resolution, which in our case would be 1080p from 4k. He mentions that without recalculation its probably close enough to not matter for most people, but technically the RPU data is incorrect and the active viewing area would also be mismatched.
-
Now that you know that, you HAVE to crop the video during processing, anything else is wrong. Since you’re going to be cropping the video, you’ll need to rerun the dovi extract command to get a version of the RPU with all offsets set to 0 (the --crop option) [Step2.2]. This, and only this RPU will be usable with your soon-to-be-cropped video.
-
To mitigate the above factor, follow the below steps.
[Cropping Option during Encoding]
Now head over to the encoding application of choice in my case its Staxrip_GUI.
- Apply a crop filter in which you will have to enter the above identified offset numbers [Step2.5]
a. Now for example if the original resolution was 3840x2610, so after taking into account the offset the new 1080p format will have 1080x804. How to arrive at this number? You crop the video for instance 276 pixels on top, 276 pixels on the bottom, then followed by a resize to 1080p (divide height and width by 2). Width: 3840 -0 offset_left -0 offset_right = 3840 / 2 = 1920. Height: 2160 -276 offset_top -276 offset_bottom = 1608 / 2 = 804. After you crop the source video 276 pixels on top and bottom, you would then do the resize step to 1920x804. When it’s done encoding, you’d inject the 2nd rpu (the one made with --crop option) [Step2.2]
[HEVC Format Extraction]
- Now we have 2 Video files with us, the “OG” and “Cropped-Encoded", you now have to copy only the hevc part of the “Cropped-Encoded” file, the command for the same is
ffmpeg -i inputfile.mkv -v error -stats -c:v copy -vbsf hevc_mp4toannexb -f hevc 'outputfile.hevc'
(change the input and output values as per your use case).
[Injecting Dolby Vision Cropped-RPU]
- The above command will now create a 3rd file of HEVC format (herein after refer to as the “Cropped-Encoded-HEVC” file), now inject the cropped RPU file containing the Dolby Metadata that you have extracted above using the GUI, unfortunately the above recommended tool doesn’t inject the metadata itself, so we will make use of Dovi_Tool for the same, run the following command (with appropriate changes as per you case)
dovi_tool inject-rpu -i /path/to/cropped-encoded-hevc.hevc --rpu-in /path/to/cropped_RPU.bin -o /path/to/injected_output-hevc.hevc
, you will now have 4 files with you, the OG | Cropped-Encoded | Cropped-Encoded-HEVC & Injected-Output-HEVC.
[Remuxing it all together]
-
Now if you check the “Injected-Output-HEVC” file with MediaInfo you will still not see the Dolby Metadata in it, but wait we now have to use TsMuxer or MKVToolNix (I prefer MKVToolNix GUI because mkv files also store Chapters which ts file do not) to mux the “Injected-Output_HEVC” file (only for the Dolby Video part) with the “OG” file for its (Audio and Subtitles and Chapters part), and after making the above selections opt for .ts or .mkv file formats and click start muxing, after completion this will now create a final file for you to preserve (herein after refer to as the “final-1080p-dolby.ts” or “final-1080p-dolby.mkv” file, you can now verify the metadata of this new file using MediaInfo and look for the HDR section and see that it should now show the Dolby Metadata with HDR 10/10+ compatibility included.
-
You may now delete the previous files created and now only preserve the 1080p file, or if your storage spares you, you may keep the “OG.mkv” & “final-1080p-dolby.ts” files and make the comparisons.
Do share your outputs in this post. We might be of some help if something goes south.
Cheers, Hope the solution helps.