kingslay / KSPlayer

A video player for iOS、macOS、tvOS、visionOS , based on AVPlayer and FFmpeg, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, SwiftUI, support subtitles.
https://apps.apple.com/app/tracyplayer/id6450770064
GNU General Public License v3.0
1.06k stars 206 forks source link

Dolby vision Issue #150

Closed Alanko5 closed 2 years ago

Alanko5 commented 3 years ago

HDR video if use one layer is good. (https://sylvan.apple.com/Aerials/2x/Videos/LA_A006_C008_2K_HDR_HEVC.mov -> is playing correctly)

But if DV use 2 layers then KSplayer not show correctly: https://user-images.githubusercontent.com/71501260/114447418-ae9e9d00-9bd2-11eb-87cd-75ca210165c3.mov

Corect visualisation: https://sheri.eu/iscc/IMG_1091.MOV

sample: https://sheri.eu/iscc/dolby-vision-amaze-(dolby-vision).mp4

KSPlayer track info: video name: und bitRate: 18057854 fps: 23.976025 bitDepth: 10 colorPrimaries: colorPrimaries: yCbCrMatrix: codecType: ehvd

Alanko5 commented 3 years ago

@kingslay please, is it possible to solve this problem?

for codecs: hev1, (edvh/dvhe), (hvcC+dvcC) for profiles: 5 and 7

kingslay commented 3 years ago

Is AVSampleBufferDisplayLayer the layer? What player did you use to play it. I used vlc, which is the same as ksplayer

Alanko5 commented 3 years ago

I use KSPlayer on AppleTV. KSPlayer not detect colorPrimaries: yCbCrMatrix:

Dolby Vision have single video layer and dual video layer:

http://bilder.hifi-forum.de/max/867239/dolby-vision-single-dual-layer_850774.png

This example use dynamic hdr metadata (Dolby Vision) and use dual (video) layer for playing. https://sheri.eu/iscc/dolby-vision-amaze-(dolby-vision).mp4

VLCKit not support HDR formats. VLCKit convert HDR to SDR. VLCKit not support DV metadata for playing.

kingslay commented 3 years ago

This can be done only if ffmpeg supports Dolby Vision dual video layer

Alanko5 commented 3 years ago

https://github.com/staxrip/staxrip/wiki/Encoding-Dolby-Vision-with-StaxRip-using-x265

https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg126853.html

Alanko5 commented 2 years ago

Dual layer dollby vision log

Infuse (use ffmpeg) support dual layer DolbyVision.

but apple tv not support. 😢

Alanko5 commented 2 years ago

@kingslay DV FEL (profile 7) Include HDR layer and dynamic metadata layer.

Can you please at least play only HDR layer?

Alanko5 commented 2 years ago

Detection for DolbyVision stream

https://github.com/MrMC/mrmc/blob/5a8e460b2aec44f03eb9604cbd7681d4277dbb81/xbmc/platform/darwin/DarwinVideoUtils.mm

case HEVC_NAL_UNSPECIFIED_63:
        // The dolby vision enhancement layer doesn't actually use NAL units 63 and 62,
        // it uses a special syntax that uses 0x7E01 and 0x7C01 as separator that makes
        // the Dolby Extension Layer (EL) appear as unspecified/unused NAL units (62 and 63),
        // but the actual NAL information starts after that extra header.
        if (nal_type_full == 0x7C01)
        {
          CLog::Log(LOGDEBUG, "%s - frame(%llu), dolby vision enhancement layer of 0x7C01 with size(%d)",
            __FUNCTION__, frameCount, nal_size);
        }
        else if (nal_type_full == 0x7E01)
          CLog::Log(LOGDEBUG, "%s - frame(%llu), dolby vision enhancement layer of 0x7E01 with size(%d)",
            __FUNCTION__, frameCount, nal_size);
        else
        {
          CLog::Log(LOGDEBUG, "%s - frame(%llu), HEVC_NAL_UNSPECIFIED_62/63 with size(%d)",
            __FUNCTION__, frameCount, nal_size);
        }
        break;

https://github.com/MrMC/mrmc/commit/5e6d1dc9e65fc64d1af9d320fcdbfa80e662f488

        // missing in ffmpeg for DolbyVison (dvhe)
        if (pStream->codec->codec_id == AV_CODEC_ID_NONE)
        {
          if (pStream->codec->codec_tag == MKTAG('d','v','h','e'))
          {
            pStream->codec->codec_id = AV_CODEC_ID_HEVC;
            CLog::Log(LOGERROR, "%s - dvhe, detected forcing AV_CODEC_ID_HEVC", __FUNCTION__);
          }
        }
        // overlap in ffmpeg of DV Video and DolbyVison (dvh1)
        // hack force it to AV_CODEC_ID_HEVC, should fix ffmpeg.
        if (pStream->codec->codec_id == AV_CODEC_ID_DVVIDEO)
        {
          if (pStream->codec->codec_tag == MKTAG('d','v','h','1'))
          {
              pStream->codec->codec_id = AV_CODEC_ID_HEVC;
              CLog::Log(LOGERROR, "%s - AV_CODEC_ID_DVVIDEO detected, forcing AV_CODEC_ID_HEVC", __FUNCTION__);
          }
        }

https://github.com/MrMC/mrmc/blob/5a8e460b2aec44f03eb9604cbd7681d4277dbb81/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp

        if (!CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEVIDEOTOOLBOX_HEVC_HDR) &&
             (hints.profile == FF_PROFILE_HEVC_MAIN_10 ||
              hints.profile == FF_PROFILE_HEVC_REXT ||
              hints.codec_tag == MKTAG('d','v','h','1') ||
              hints.codec_tag == MKTAG('d','v','h','e') ||
              hints.codec_tag == MKTAG('D','O','V','I')))
        {
          // if bt2020+, kick it to AVFoundataion
          if (hints.colortransfer >= AVCOL_TRC_SMPTE2084)
            return false;
          // only AVFoundataion can handle DolbyVision
          if (hints.codec_tag == MKTAG('d','v','h','1') ||
              hints.codec_tag == MKTAG('d','v','h','e') ||
              hints.codec_tag == MKTAG('D','O','V','I'))
            return false;
        }