Skip to content

Commit

Permalink
Add VideoDoViTitle to display DV compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nyanmisaka committed Jun 24, 2022
1 parent 7579b18 commit 998edad
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
20 changes: 11 additions & 9 deletions MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ private bool IsHwTonemapAvailable(EncodingJobInfo state, EncodingOptions options
return false;
}

if (string.Equals(state.VideoStream.CodecTag, "dovi", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.VideoStream.CodecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.VideoStream.CodecTag, "dvhe", StringComparison.OrdinalIgnoreCase))
if (string.Equals(state.VideoStream.Codec, "hevc", StringComparison.OrdinalIgnoreCase)
&& string.Equals(state.VideoStream.VideoRange, "HDR", StringComparison.OrdinalIgnoreCase)
&& string.Equals(state.VideoStream.VideoRangeType, "DOVI", StringComparison.OrdinalIgnoreCase))
{
// Only native SW decoder and HW accelerator can parse dovi rpu.
var vidDecoder = GetHardwareVideoDecoder(state, options) ?? string.Empty;
Expand All @@ -170,22 +170,24 @@ private bool IsHwTonemapAvailable(EncodingJobInfo state, EncodingOptions options
return isSwDecoder || isNvdecDecoder || isVaapiDecoder || isD3d11vaDecoder;
}

return string.Equals(state.VideoStream.ColorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.VideoStream.ColorTransfer, "arib-std-b67", StringComparison.OrdinalIgnoreCase);
return string.Equals(state.VideoStream.VideoRange, "HDR", StringComparison.OrdinalIgnoreCase)
&& (string.Equals(state.VideoStream.VideoRangeType, "HDR10", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.VideoStream.VideoRangeType, "HLG", StringComparison.OrdinalIgnoreCase));
}

private bool IsVaapiVppTonemapAvailable(EncodingJobInfo state, EncodingOptions options)
{
if (state.VideoStream == null)
if (state.VideoStream == null
|| !options.EnableVppTonemapping
|| GetVideoColorBitDepth(state) != 10)
{
return false;
}

// Native VPP tonemapping may come to QSV in the future.

return options.EnableVppTonemapping
&& string.Equals(state.VideoStream.ColorTransfer, "smpte2084", StringComparison.OrdinalIgnoreCase)
&& GetVideoColorBitDepth(state) == 10;
return string.Equals(state.VideoStream.VideoRange, "HDR", StringComparison.OrdinalIgnoreCase)
&& string.Equals(state.VideoStream.VideoRangeType, "HDR10", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
Expand Down
53 changes: 50 additions & 3 deletions MediaBrowser.Model/Entities/MediaStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,47 @@ public string VideoRangeType
}
}

/// <summary>
/// Gets the video dovi title.
/// </summary>
/// <value>The video dovi title.</value>
public string VideoDoViTitle
{
get
{
var dvProfile = DvProfile;
var rpuPresentFlag = RpuPresentFlag == 1;
var blPresentFlag = BlPresentFlag == 1;
var dvBlCompatId = DvBlSignalCompatibilityId;

if (rpuPresentFlag
&& blPresentFlag
&& (dvProfile == 4
|| dvProfile == 5
|| dvProfile == 7
|| dvProfile == 8
|| dvProfile == 9))
{
var title = "DV Profile " + dvProfile;

if (dvBlCompatId > 0)
{
title += "." + dvBlCompatId;
}

return dvBlCompatId switch
{
1 => title + " (HDR10)",
2 => title + " (SDR)",
4 => title + " (HLG)",
_ => title
};
}

return null;
}
}

public string LocalizedUndefined { get; set; }

public string LocalizedDefault { get; set; }
Expand Down Expand Up @@ -630,11 +671,17 @@ public bool SupportsSubtitleConversionTo(string toCodec)
return ("HDR", "HLG");
}

// For some Dolby Vision files, no color transfer is provided, so check the codec

var codecTag = CodecTag;
var dvProfile = DvProfile;
var rpuPresentFlag = RpuPresentFlag == 1;
var blPresentFlag = BlPresentFlag == 1;
var dvBlCompatId = DvBlSignalCompatibilityId;

var isDoViHDRProfile = dvProfile == 5 || dvProfile == 7 || dvProfile == 8;
var isDoViHDRFlag = rpuPresentFlag && blPresentFlag && (dvBlCompatId == 0 || dvBlCompatId == 1 || dvBlCompatId == 4);

if (string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
if ((isDoViHDRProfile && isDoViHDRFlag)
|| string.Equals(codecTag, "dovi", StringComparison.OrdinalIgnoreCase)
|| string.Equals(codecTag, "dvh1", StringComparison.OrdinalIgnoreCase)
|| string.Equals(codecTag, "dvhe", StringComparison.OrdinalIgnoreCase)
|| string.Equals(codecTag, "dav1", StringComparison.OrdinalIgnoreCase))
Expand Down

0 comments on commit 998edad

Please sign in to comment.