Fixed: Detect Dolby Vision as HDR

Co-Authored-By: Taloth <Taloth@users.noreply.github.com>

#5860
This commit is contained in:
Matt Evans 2021-02-03 12:19:22 +11:00 committed by Qstick
parent 6702c7d21b
commit d8c962a911
5 changed files with 32 additions and 13 deletions

View File

@ -8,20 +8,28 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
[TestFixture]
public class FormatVideoDynamicRangeFixture : TestBase
{
[TestCase(8, "BT.601 NTSC", "BT.709", "")]
[TestCase(10, "BT.2020", "PQ", "HDR")]
[TestCase(8, "BT.2020", "PQ", "")]
[TestCase(10, "BT.601 NTSC", "PQ", "")]
[TestCase(10, "BT.2020", "BT.709", "")]
[TestCase(10, "BT.2020", "HLG", "HDR")]
public void should_format_video_dynamic_range(int bitDepth, string colourPrimaries, string transferCharacteristics, string expectedVideoDynamicRange)
[TestCase(8, "", "", "", "", "")]
[TestCase(8, "BT.601 NTSC", "BT.709", "", "", "")]
[TestCase(10, "BT.2020", "PQ", "", "", "HDR")]
[TestCase(8, "BT.2020", "PQ", "", "", "")]
[TestCase(10, "BT.601 NTSC", "PQ", "", "", "")]
[TestCase(10, "BT.2020", "BT.709", "", "", "")]
[TestCase(10, "BT.2020", "HLG", "", "", "HDR")]
[TestCase(10, "", "", "Dolby Vision", "", "HDR")]
[TestCase(10, "", "", "SMPTE ST 2086", "HDR10", "HDR")]
[TestCase(8, "", "", "Dolby Vision", "", "HDR")]
[TestCase(8, "", "", "SMPTE ST 2086", "HDR10", "HDR")]
[TestCase(10, "BT.2020", "PQ", "Dolby Vision / SMPTE ST 2086", "Blu-ray / HDR10", "HDR")]
public void should_format_video_dynamic_range(int bitDepth, string colourPrimaries, string transferCharacteristics, string hdrFormat, string hdrFormatCompatibility, string expectedVideoDynamicRange)
{
var mediaInfo = new MediaInfoModel
{
VideoBitDepth = bitDepth,
VideoColourPrimaries = colourPrimaries,
VideoTransferCharacteristics = transferCharacteristics,
SchemaRevision = 5
VideoHdrFormat = hdrFormat,
VideoHdrFormatCompatibility = hdrFormatCompatibility,
SchemaRevision = 7
};
MediaInfoFormatter.FormatVideoDynamicRange(mediaInfo).Should().Be(expectedVideoDynamicRange);

View File

@ -65,6 +65,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo
info.VideoColourPrimaries.Should().Be("BT.601 NTSC");
info.VideoTransferCharacteristics.Should().Be("BT.709");
info.AudioAdditionalFeatures.Should().BeOneOf("", "LC");
info.VideoHdrFormat.Should().BeEmpty();
info.VideoHdrFormatCompatibility.Should().BeEmpty();
}
[Test]
@ -106,6 +108,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo
info.VideoColourPrimaries.Should().Be("BT.601 NTSC");
info.VideoTransferCharacteristics.Should().Be("BT.709");
info.AudioAdditionalFeatures.Should().BeOneOf("", "LC");
info.VideoHdrFormat.Should().BeEmpty();
info.VideoHdrFormatCompatibility.Should().BeEmpty();
}
[Test]

View File

@ -13,6 +13,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
public static class MediaInfoFormatter
{
private const string ValidHdrColourPrimaries = "BT.2020";
private const string VideoDynamicRangeHdr = "HDR";
private static readonly string[] ValidHdrTransferFunctions = { "PQ", "HLG" };
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(MediaInfoFormatter));
@ -602,8 +603,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
public static string FormatVideoDynamicRange(MediaInfoModel mediaInfo)
{
// assume SDR by default
var videoDynamicRange = "";
if (mediaInfo.VideoHdrFormat.IsNotNullOrWhiteSpace())
{
return VideoDynamicRangeHdr;
}
if (mediaInfo.VideoBitDepth >= 10 &&
mediaInfo.VideoColourPrimaries.IsNotNullOrWhiteSpace() &&
@ -612,11 +615,11 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
if (mediaInfo.VideoColourPrimaries.EqualsIgnoreCase(ValidHdrColourPrimaries) &&
ValidHdrTransferFunctions.Any(mediaInfo.VideoTransferCharacteristics.Contains))
{
videoDynamicRange = "HDR";
return VideoDynamicRangeHdr;
}
}
return videoDynamicRange;
return "";
}
}
}

View File

@ -18,6 +18,8 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
public int VideoMultiViewCount { get; set; }
public string VideoColourPrimaries { get; set; }
public string VideoTransferCharacteristics { get; set; }
public string VideoHdrFormat { get; set; }
public string VideoHdrFormatCompatibility { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public string AudioFormat { get; set; }

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private readonly Logger _logger;
public const int MINIMUM_MEDIA_INFO_SCHEMA_REVISION = 4;
public const int CURRENT_MEDIA_INFO_SCHEMA_REVISION = 6;
public const int CURRENT_MEDIA_INFO_SCHEMA_REVISION = 7;
public VideoFileInfoReader(IDiskProvider diskProvider, Logger logger)
{
@ -164,6 +164,8 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
VideoMultiViewCount = videoMultiViewCount,
VideoColourPrimaries = mediaInfo.Get(StreamKind.Video, 0, "colour_primaries"),
VideoTransferCharacteristics = mediaInfo.Get(StreamKind.Video, 0, "transfer_characteristics"),
VideoHdrFormat = mediaInfo.Get(StreamKind.Video, 0, "HDR_Format"),
VideoHdrFormatCompatibility = mediaInfo.Get(StreamKind.Video, 0, "HDR_Format_Compatibility"),
Height = height,
Width = width,
AudioFormat = mediaInfo.Get(StreamKind.Audio, 0, "Format"),