rigaya / NVEnc

NVENCによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-17.html
Other
1.03k stars 108 forks source link

HDR + Dolby Vision #402

Open jriker1 opened 2 years ago

jriker1 commented 2 years ago

I have some footage that seems to contain both HDR10 and Dolby Vision. Does this look accurate?

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

Or is this just Dolby Vision and if the device doesn't support it can look at the info like HDR10? If they both are in this file, can they be re-encoded into a new file with nvencc?

rigaya commented 2 years ago

I suppose this is an output of MediaInfo, but it's not possible for me to tell if it is accurate or not.

Dolby Vision support in nvencc is limited and can handle only single-layer profiles. As it seems like it is single-layer (dovi rpu metadata + HDR10 static metadata), it might be possible to handle it.

Gedeon90 commented 1 year ago

Hi there. Firts of all congrats, the tool is really great.

I'm dealing with the same issue, and I'm not an expert, but I've been able to get this info from ffprobe. I think the "trick" is adding/copying a "side_data_list" property from the original hevc dolby vision compatible stream in the source file, when dolby vision option is used.

In the example you can see the json ouput from source file from which rpu could be extracted. This file is fully compatible with dolby vision. However, mkv files generated with NVEncc64 don't get those tags

Thanks in advance!


{
    "streams": [
        {
            "index": 0,
            "codec_name": "hevc",
            "codec_long_name": "H.265 / HEVC (High Efficiency Video Coding)",
            "profile": "Main 10",
            "codec_type": "video",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "width": 3840,
            "height": 2160,
            "coded_width": 3840,
            "coded_height": 2160,
            "closed_captions": 0,
            "film_grain": 0,
            "has_b_frames": 3,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p10le",
            "level": 153,
            "color_range": "tv",
            "color_space": "bt2020nc",
            "color_transfer": "smpte2084",
            "color_primaries": "bt2020",
            "chroma_location": "topleft",
            "refs": 1,
            "r_frame_rate": "24000/1001",
            "avg_frame_rate": "24000/1001",
            "time_base": "1/1000",
            "start_pts": 0,
            "start_time": "0.000000",
            "extradata_size": 207,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "BPS": "47404839",
                "DURATION": "02:06:57.527000000",
                "NUMBER_OF_FRAMES": "182638",
                "NUMBER_OF_BYTES": "45138455145",
                "_STATISTICS_WRITING_APP": "mkvmerge v64.0.0 ('Willows') 64-bit",
                "_STATISTICS_WRITING_DATE_UTC": "2022-03-30 11:18:12",
                "_STATISTICS_TAGS": "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"
            },
            "side_data_list": [
                {
                    "side_data_type": "DOVI configuration record",
                    "dv_version_major": 1,
                    "dv_version_minor": 0,
                    "dv_profile": 8,
                    "dv_level": 6,
                    "rpu_present_flag": 1,
                    "el_present_flag": 0,
                    "bl_present_flag": 1,
                    "dv_bl_signal_compatibility_id": 1
                }
            ]
        }
    ],
    "format": {
        "filename": "XXXXX.mkv",
        "nb_streams": 11,
        "nb_programs": 0,
        "format_name": "matroska,webm",
        "format_long_name": "Matroska / WebM",
        "start_time": "0.000000",
        "duration": "7617.558000",
        "size": "54539024808",
        "bit_rate": "57277174",
        "probe_score": 100,
        "tags": {
            "title": "XXXX",
            "encoder": "libebml v1.4.2 + libmatroska v1.6.4",
            "creation_time": "2022-03-30T11:18:12.000000Z"
        }
    }
}
...
jriker1 commented 1 year ago

Here is what I ended up doing to get both the HDR10 and Dolby Vision content. Seems to work and the data is there:

NVEncC64.exe --avhw --input input.mkv --output output.hevc --codec h265 --tier high --level 5.1 --output-depth 10 --cqp 19 --preset quality --vbv-bufsize 15000 --lookahead 32 --bframes 4 --aq-temporal --aud --repeat-headers --chromaloc 2 --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --colorrange limited --max-cll 413,65 --master-display copy --video-metadata copy --crop 0,280,0,280 --gop-len 0 --ref 3 --profile main10 --bref-mode middle --mv-precision Q-pel

(Note I manually set the max-cll info as don't know that copying the master-display info includes that. Don't think so.)

Gedeon90 commented 1 year ago

Thanks for the info and the insight about max-cll. I'll check it.

This tool (https://forum.doom9.org/showthread.php?t=183479) seems to do it in a more automated way. Mkvmerge seems to do the "magic" in parsing the DV metadata and adding the headers to the hevc stream in a way mediainfo, ffprobe and players admit.

I'm also curious about "--ref 3" and "--bref-mode middle" ¿ Have you observed improvements in saving space/increasing quality ?

These are my current "high quality" constant parameters --mv-precision Q-pel --preset p7 --bref-mode each --multipass 2pass-full --bframes 4 --ref 16 --gop-len 120

And also curious about non rpu cropping. In the script I've linked the author also performs a crop in the rpu.bin

jriker1 commented 1 year ago

Never thought about that if understanding. Do we think if you like crop black bars on the top and bottom that the dolby vision data exported isn't valid when injecting back into the final video? I don't honestly know a lot about some of the attributes I use, just researching online a compilation of similar recommendations and where there were a lot of synergies went with them.

Right now I'm struggling with encoding settings. Have another issue open that contains images of that. I like to have a keep for watching and a keep for I love this video setting. Before it was my CRF value. Now looking at CQP. CRF was always odd to me that the value suggested was lower (higher number) for 4k than 1080p. not sure if that's because of the presumption 4k content is cleaner so less pixelation. In my other post here it's hard for me to see in the actual video differences form 16 up to 28 for CQP. I do see smoothing in the background but hard to see differences in people in the video. For me anyway but that's on a small screen.

lgoncal commented 1 year ago

Do we think if you like crop black bars on the top and bottom that the dolby vision data exported isn't valid That is correct. If you crop the video you must adjust (crop) the DoVi metadata