diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index e98a7de..6195635 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -300,6 +300,39 @@ MP42_OBJC_DIRECT_MEMBERS } } + if (@available(macOS 10.13, *)) { + CFDictionaryRef extentions = CMFormatDescriptionGetExtensions(formatDescription); + CFDictionaryRef atoms = CFDictionaryGetValue(extentions, kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms); + CFDataRef dvExtension = CFDictionaryGetValue(atoms, @"dvcC"); + + if (!dvExtension) { + dvExtension = CFDictionaryGetValue(atoms, @"dvvC"); + } + if (!dvExtension) { + dvExtension = CFDictionaryGetValue(atoms, @"dvwC"); + } + + if (dvExtension && CFDataGetLength(dvExtension) >= 24) { + MP42DolbyVisionMetadata dv; + uint8_t buffer[24]; + CFDataGetBytes(dvExtension, CFRangeMake(0, 24), buffer); + + dv.versionMajor = buffer[0]; + dv.versionMinor = buffer[1]; + + dv.profile = (buffer[2] & 0xfe) >> 1; + dv.level = ((buffer[2] & 0x1) << 7) + ((buffer[3] & 0xf8) >> 3); + + dv.rpuPresentFlag = (buffer[3] & 0x4) >> 2; + dv.elPresentFlag = (buffer[3] & 0x2) >> 1; + dv.blPresentFlag = buffer[3] & 0x1; + + dv.blSignalCompatibilityId = (buffer[4] & 0xf0) >> 4; + + videoTrack.dolbyVision = dv; + } + } + } newTrack = videoTrack; diff --git a/MP42/MP42DolbyVisionMetadata.h b/MP42/MP42DolbyVisionMetadata.h new file mode 100644 index 0000000..aa38450 --- /dev/null +++ b/MP42/MP42DolbyVisionMetadata.h @@ -0,0 +1,23 @@ +// +// MP42DolbyVisionMetadata.h +// MP42Foundation +// +// Created by Damiano Galassi on 07/12/21. +// Copyright © 2021 Damiano Galassi. All rights reserved. +// + +#ifndef MP42DolbyVisionMetadata_h +#define MP42DolbyVisionMetadata_h + +typedef struct MP42DolbyVisionMetadata { + uint8_t versionMajor; + uint8_t versionMinor; + uint8_t profile; + uint8_t level; + bool rpuPresentFlag; + bool elPresentFlag; + bool blPresentFlag; + uint8_t blSignalCompatibilityId; +} MP42DolbyVisionMetadata; + +#endif /* MP42DolbyVisionMetadata_h */ diff --git a/MP42/MP42VideoTrack.h b/MP42/MP42VideoTrack.h index 33c62b7..60fcb95 100644 --- a/MP42/MP42VideoTrack.h +++ b/MP42/MP42VideoTrack.h @@ -9,6 +9,7 @@ #import #import #import +#import @interface MP42VideoTrack : MP42Track @@ -30,6 +31,9 @@ @property(nonatomic, readwrite) MP42MasteringDisplayMetadata mastering; @property(nonatomic, readwrite) MP42ContentLightMetadata coll; +// Dolby Vision +@property(nonatomic, readwrite) MP42DolbyVisionMetadata dolbyVision; + // Pixel Aspect Ratio @property(nonatomic, readwrite) uint64_t hSpacing; @property(nonatomic, readwrite) uint64_t vSpacing; diff --git a/MP42/MP42VideoTrack.m b/MP42/MP42VideoTrack.m index 8f72064..f383c17 100644 --- a/MP42/MP42VideoTrack.m +++ b/MP42/MP42VideoTrack.m @@ -125,6 +125,69 @@ MP42_OBJC_DIRECT_MEMBERS _mastering.has_luminance = 1; } + if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC")) { + uint64_t versionMajor, versionMinor, profile, level, rpuPresentFlag, elPresentFlag, blPresentFlag, blSignalCompatibilityId; + + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.dv_version_major", &versionMajor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.dv_version_minor", &versionMinor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.dv_profile", &profile); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.dv_level", &level); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.rpu_present_flag", &rpuPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.el_present_flag", &elPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.bl_present_flag", &blPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvcC.dv_bl_signal_compatibility_id", &blSignalCompatibilityId); + + _dolbyVision.versionMajor = versionMajor; + _dolbyVision.versionMinor = versionMinor; + _dolbyVision.profile = profile; + _dolbyVision.level = level; + _dolbyVision.rpuPresentFlag = rpuPresentFlag; + _dolbyVision.elPresentFlag = elPresentFlag; + _dolbyVision.blPresentFlag = blPresentFlag; + _dolbyVision.blSignalCompatibilityId = blSignalCompatibilityId; + } + else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC")) { + uint64_t versionMajor, versionMinor, profile, level, rpuPresentFlag, elPresentFlag, blPresentFlag, blSignalCompatibilityId; + + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.dv_version_major", &versionMajor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.dv_version_minor", &versionMinor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.dv_profile", &profile); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.dv_level", &level); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.rpu_present_flag", &rpuPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.el_present_flag", &elPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.bl_present_flag", &blPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvvC.dv_bl_signal_compatibility_id", &blSignalCompatibilityId); + + _dolbyVision.versionMajor = versionMajor; + _dolbyVision.versionMinor = versionMinor; + _dolbyVision.profile = profile; + _dolbyVision.level = level; + _dolbyVision.rpuPresentFlag = rpuPresentFlag; + _dolbyVision.elPresentFlag = elPresentFlag; + _dolbyVision.blPresentFlag = blPresentFlag; + _dolbyVision.blSignalCompatibilityId = blSignalCompatibilityId; + } + else if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC")) { + uint64_t versionMajor, versionMinor, profile, level, rpuPresentFlag, elPresentFlag, blPresentFlag, blSignalCompatibilityId; + + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.dv_version_major", &versionMajor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.dv_version_minor", &versionMinor); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.dv_profile", &profile); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.dv_level", &level); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.rpu_present_flag", &rpuPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.el_present_flag", &elPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.bl_present_flag", &blPresentFlag); + MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.dvwC.dv_bl_signal_compatibility_id", &blSignalCompatibilityId); + + _dolbyVision.versionMajor = versionMajor; + _dolbyVision.versionMinor = versionMinor; + _dolbyVision.profile = profile; + _dolbyVision.level = level; + _dolbyVision.rpuPresentFlag = rpuPresentFlag; + _dolbyVision.elPresentFlag = elPresentFlag; + _dolbyVision.blPresentFlag = blPresentFlag; + _dolbyVision.blSignalCompatibilityId = blSignalCompatibilityId; + } if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap")) { MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", &_cleanApertureWidthN); MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", &_cleanApertureWidthD); @@ -411,6 +474,21 @@ static uint32_t convertToFixedPoint(CGFloat value) { } } +- (NSString *)formatSummary +{ + NSMutableString *summary = [super.formatSummary mutableCopy]; + if (_mastering.has_luminance && _mastering.has_primaries) { + [summary appendString:@" HDR10"]; + } + if (_dolbyVision.versionMajor) { + if (![summary containsString:@"Dolby Vision"]) { + [summary appendString:@" Dolby Vision"]; + } + [summary appendFormat:@" %d.%d", _dolbyVision.profile, _dolbyVision.level]; + } + return summary; +} + #pragma mark - NSCopying - (instancetype)copyWithZone:(NSZone *)zone @@ -432,6 +510,7 @@ static uint32_t convertToFixedPoint(CGFloat value) { copy->_mastering = _mastering; copy->_coll = _coll; + copy->_dolbyVision = _dolbyVision; copy->_hSpacing = _hSpacing; copy->_vSpacing = _vSpacing; @@ -507,6 +586,15 @@ static uint32_t convertToFixedPoint(CGFloat value) { [coder encodeInt64:_hSpacing forKey:@"hSpacing"]; [coder encodeInt64:_vSpacing forKey:@"vSpacing"]; + [coder encodeInt32:_dolbyVision.versionMajor forKey:@"DVversionMajor"]; + [coder encodeInt32:_dolbyVision.versionMinor forKey:@"DVversionMinor"]; + [coder encodeInt32:_dolbyVision.profile forKey:@"DVprofile"]; + [coder encodeInt32:_dolbyVision.level forKey:@"DVlevel"]; + [coder encodeInt32:_dolbyVision.rpuPresentFlag forKey:@"DVrpuPresentFlag"]; + [coder encodeInt32:_dolbyVision.elPresentFlag forKey:@"DVelPresentFlag"]; + [coder encodeInt32:_dolbyVision.blPresentFlag forKey:@"DVblPresentFlag"]; + [coder encodeInt32:_dolbyVision.blSignalCompatibilityId forKey:@"DVblSignalCompatibilityId"]; + [coder encodeDouble:_transform.a forKey:@"transformA"]; [coder encodeDouble:_transform.b forKey:@"transformB"]; [coder encodeDouble:_transform.c forKey:@"transformC"]; @@ -563,6 +651,15 @@ static uint32_t convertToFixedPoint(CGFloat value) { _coll.MaxCLL = (uint32_t)[decoder decodeInt64ForKey:@"maxCLL"]; _coll.MaxFALL = (uint32_t)[decoder decodeInt64ForKey:@"maxFALL"]; + _dolbyVision.versionMajor = [decoder decodeInt32ForKey:@"DVversionMajor"]; + _dolbyVision.versionMinor = [decoder decodeInt32ForKey:@"DVversionMinor"]; + _dolbyVision.profile = [decoder decodeInt32ForKey:@"DVprofile"]; + _dolbyVision.level = [decoder decodeInt32ForKey:@"DVlevel"]; + _dolbyVision.rpuPresentFlag = [decoder decodeInt32ForKey:@"DVrpuPresentFlag"]; + _dolbyVision.elPresentFlag = [decoder decodeInt32ForKey:@"DVelPresentFlag"]; + _dolbyVision.blPresentFlag = [decoder decodeInt32ForKey:@"DVblPresentFlag"]; + _dolbyVision.blSignalCompatibilityId = [decoder decodeInt32ForKey:@"DVblSignalCompatibilityId"]; + _hSpacing = [decoder decodeInt64ForKey:@"hSpacing"]; _vSpacing = [decoder decodeInt64ForKey:@"vSpacing"]; diff --git a/MP42Foundation.xcodeproj/project.pbxproj b/MP42Foundation.xcodeproj/project.pbxproj index a0811e8..719be85 100644 --- a/MP42Foundation.xcodeproj/project.pbxproj +++ b/MP42Foundation.xcodeproj/project.pbxproj @@ -152,6 +152,8 @@ A9A0C9A419814C9B00A72763 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9A0C9A319814C9B00A72763 /* AudioUnit.framework */; }; A9A268E2196D6367003AFF57 /* MP42EditListsReconstructor.m in Sources */ = {isa = PBXBuildFile; fileRef = A9DFBDCA1960174500410060 /* MP42EditListsReconstructor.m */; }; A9AA2B821DBF954000C9D897 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A9AA2B841DBF954000C9D897 /* Localizable.strings */; }; + A9AAD4FF275F935D00E586F6 /* MP42DolbyVisionMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = A9AAD4FE275F935D00E586F6 /* MP42DolbyVisionMetadata.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A9AAD500275F935D00E586F6 /* MP42DolbyVisionMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = A9AAD4FE275F935D00E586F6 /* MP42DolbyVisionMetadata.h */; }; A9AEFE151B9B111B00771292 /* MP42FileImporter+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A9AEFE141B9B111B00771292 /* MP42FileImporter+Private.h */; }; A9AEFE161B9B111B00771292 /* MP42FileImporter+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A9AEFE141B9B111B00771292 /* MP42FileImporter+Private.h */; }; A9B0F28922A29E9C0012E099 /* liblzma.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A9B0F28822A29E9C0012E099 /* liblzma.tbd */; }; @@ -328,6 +330,7 @@ A9A0C99B19814B0800A72763 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; A9A0C9A319814C9B00A72763 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; A9AA2B831DBF954000C9D897 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = ""; }; + A9AAD4FE275F935D00E586F6 /* MP42DolbyVisionMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MP42DolbyVisionMetadata.h; sourceTree = ""; }; A9AEFE141B9B111B00771292 /* MP42FileImporter+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MP42FileImporter+Private.h"; sourceTree = ""; }; A9B0F28822A29E9C0012E099 /* liblzma.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = liblzma.tbd; path = usr/lib/liblzma.tbd; sourceTree = SDKROOT; }; A9B0F2B322A2A36D0012E099 /* libpng16.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpng16.a; path = contrib/Tesseract/lib/libpng16.a; sourceTree = ""; }; @@ -719,6 +722,7 @@ A941C95D1F82A9B800FC5E8D /* MP42SSAConverter.m */, A9762BAC2660D71E0055E0B3 /* MP42Rational.h */, A9762BAD2660D71E0055E0B3 /* MP42Rational.c */, + A9AAD4FE275F935D00E586F6 /* MP42DolbyVisionMetadata.h */, A9762BA62660CF590055E0B3 /* MP42MasteringDisplayMetadata.h */, A96523431BAC315900E994E0 /* NSString+MP42Additions.h */, A96523441BAC315900E994E0 /* NSString+MP42Additions.m */, @@ -777,6 +781,7 @@ A9ED5B0E1F824A9B00E0E4FA /* MP42SSAParser.h in Headers */, A99FCBC51BAD65EF0058E27A /* MP42Track+Private.h in Headers */, A9AEFE161B9B111B00771292 /* MP42FileImporter+Private.h in Headers */, + A9AAD500275F935D00E586F6 /* MP42DolbyVisionMetadata.h in Headers */, A96523461BAC315900E994E0 /* NSString+MP42Additions.h in Headers */, A941C9571F82996600FC5E8D /* MP42TextSubConverter.h in Headers */, A908011A1D4B83A3002B6950 /* MP42AudioUnit.h in Headers */, @@ -805,6 +810,7 @@ A9022A941D6F3FD9005F0920 /* MP42MetadataItem.h in Headers */, A9B9C2871823923200416A4E /* MP42Metadata.h in Headers */, A9B9C2851823923200416A4E /* MP42MediaFormat.h in Headers */, + A9AAD4FF275F935D00E586F6 /* MP42DolbyVisionMetadata.h in Headers */, A989F10F1823B3B40070AD8C /* MP42TextSample.h in Headers */, A9B9C2831823923200416A4E /* MP42Image.h in Headers */, A9B9C2C41823957800416A4E /* MP42Languages.h in Headers */,