Read Dolby Vision metadata from mp4 and mov.

This commit is contained in:
Damiano Galassi committed 2021-12-07 15:19:00 +01:00
1 parent 6d2c29ed94
commit 85790a5f41
5 files changed
+163

No files matched your search

+33
View File
@@ -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;
+23
View File
@@ -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 */
+4
View File
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import <MP42Foundation/MP42Track.h>
#import <MP42Foundation/MP42MasteringDisplayMetadata.h>
#import <MP42Foundation/MP42DolbyVisionMetadata.h>
@interface MP42VideoTrack : MP42Track <NSSecureCoding, NSCopying>
@@ -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;
+97
View File
@@ -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"];