Passthru the HDR10 metadata.

This commit is contained in:
Damiano Galassi committed 2021-05-28 14:56:10 +02:00
1 parent b1b5985c2a
commit eb410ed7a4
8 files changed
+547 -36

No files matched your search

+42
View File
@@ -258,6 +258,48 @@ MP42_OBJC_DIRECT_MEMBERS
if (colorRange) {
videoTrack.colorRange = CFBooleanGetValue(colorRange);
}
if (@available(macOS 10.13, *)) {
CFDataRef masteringExtension = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_MasteringDisplayColorVolume);
if (masteringExtension && CFDataGetLength(masteringExtension) >= 24) {
MP42MasteringDisplayMetadataPayload *masteringPayload = (MP42MasteringDisplayMetadataPayload *)CFDataGetBytePtr(masteringExtension);
MP42MasteringDisplayMetadata mastering;
const int chromaDen = 50000;
const int lumaDen = 10000;
mastering.display_primaries[0][0] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_rx), chromaDen);
mastering.display_primaries[0][1] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_ry), chromaDen);
mastering.display_primaries[1][0] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_gx), chromaDen);
mastering.display_primaries[1][1] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_gy), chromaDen);
mastering.display_primaries[2][0] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_bx), chromaDen);
mastering.display_primaries[2][1] = make_rational(CFSwapInt16BigToHost(masteringPayload->display_primaries_by), chromaDen);
mastering.white_point[0] = make_rational(CFSwapInt16BigToHost(masteringPayload->white_point_x), chromaDen);
mastering.white_point[1] = make_rational(CFSwapInt16BigToHost(masteringPayload->white_point_y), chromaDen);
mastering.max_luminance = make_rational(CFSwapInt32BigToHost(masteringPayload->max_display_mastering_luminance), lumaDen);
mastering.min_luminance = make_rational(CFSwapInt32BigToHost(masteringPayload->min_display_mastering_luminance), lumaDen);
mastering.has_primaries = 1;
mastering.has_luminance = 1;
videoTrack.mastering = mastering;
}
}
if (@available(macOS 10.13, *)) {
CFDataRef collExtension = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_ContentLightLevelInfo);
if (collExtension && CFDataGetLength(collExtension) >= 4) {
MP42ContentLightMetadataPayload *collPayload = (MP42ContentLightMetadataPayload *)CFDataGetBytePtr(collExtension);
MP42ContentLightMetadata coll;
coll.MaxCLL = CFSwapInt16BigToHost(collPayload->MaxCLL);
coll.MaxFALL = CFSwapInt16BigToHost(collPayload->MaxFALL);
videoTrack.coll = coll;
}
}
}
newTrack = videoTrack;
+49
View File
@@ -0,0 +1,49 @@
//
// MP42MasteringDisplayMetadata.h
// MP42Foundation
//
// Created by Damiano Galassi on 28/05/21.
// Copyright © 2021 Damiano Galassi. All rights reserved.
//
#ifndef MP42MasteringDisplayMetadata_h
#define MP42MasteringDisplayMetadata_h
#include <MP42Foundation/MP42Rational.h>
typedef struct MP42MasteringDisplayMetadata {
MP42Rational display_primaries[3][2];
MP42Rational white_point[2];
MP42Rational min_luminance;
MP42Rational max_luminance;
int32_t has_primaries;
int32_t has_luminance;
} MP42MasteringDisplayMetadata;
typedef struct MP42ContentLightMetadata {
uint32_t MaxCLL;
uint32_t MaxFALL;
} MP42ContentLightMetadata;
// matches payload of ISO/IEC 23008-2:2015(E), D.2.28 Mastering display colour volume SEI message
typedef struct MP42MasteringDisplayMetadataPayload {
uint16_t display_primaries_gx;
uint16_t display_primaries_gy;
uint16_t display_primaries_bx;
uint16_t display_primaries_by;
uint16_t display_primaries_rx;
uint16_t display_primaries_ry;
uint16_t white_point_x;
uint16_t white_point_y;
uint32_t max_display_mastering_luminance;
uint32_t min_display_mastering_luminance;
} MP42MasteringDisplayMetadataPayload;
typedef struct MP42ContentLightMetadataPayload {
uint16_t MaxCLL;
uint16_t MaxFALL;
} MP42ContentLightMetadataPayload;
#endif /* MP42MasteringDisplayMetadata_h */
+38
View File
@@ -153,6 +153,44 @@ MP42_OBJC_DIRECT_MEMBERS
videoTrack.colorRange = mkvTrack->AV.Video.Colour.Range == 2 ? 1 : 0;
}
MP42MasteringDisplayMetadata mastering;
bzero(&mastering, sizeof(MP42MasteringDisplayMetadata));
if (mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryRChromaticityX &&
mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryRChromaticityY &&
mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryGChromaticityX &&
mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryGChromaticityY &&
mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityX &&
mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityY) {
mastering.display_primaries[0][0] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryRChromaticityX, INT_MAX);
mastering.display_primaries[0][1] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryRChromaticityY, INT_MAX);
mastering.display_primaries[1][0] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryGChromaticityX, INT_MAX);
mastering.display_primaries[1][1] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryGChromaticityY, INT_MAX);
mastering.display_primaries[2][0] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityX, INT_MAX);
mastering.display_primaries[2][1] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.PrimaryBChromaticityY, INT_MAX);
mastering.white_point[0] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.WhitePointChromaticityX, INT_MAX);
mastering.white_point[1] = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.WhitePointChromaticityY, INT_MAX);
mastering.has_primaries = 1;
}
if (mkvTrack->AV.Video.Colour.MasteringMetadata.LuminanceMin && mkvTrack->AV.Video.Colour.MasteringMetadata.LuminanceMax) {
mastering.min_luminance = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.LuminanceMin, INT_MAX);
mastering.max_luminance = mp42_d2q(mkvTrack->AV.Video.Colour.MasteringMetadata.LuminanceMax, INT_MAX);
mastering.has_luminance = 1;
}
if (mastering.has_primaries && mastering.has_luminance) {
videoTrack.mastering = mastering;
}
if (mkvTrack->AV.Video.Colour.MaxCLL && mkvTrack->AV.Video.Colour.MaxFALL)
{
MP42ContentLightMetadata coll;
coll.MaxCLL = mkvTrack->AV.Video.Colour.MaxCLL;
coll.MaxFALL = mkvTrack->AV.Video.Colour.MaxFALL;
videoTrack.coll = coll;
}
newTrack = videoTrack;
}
+176
View File
@@ -0,0 +1,176 @@
//
// MP42Rational.c
// MP42Foundation
//
// Taken from FFmpeg AVRational
#include "MP42Rational.h"
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
int64_t mp42_gcd(int64_t a, int64_t b) {
int za, zb, k;
int64_t u, v;
if (a == 0)
return b;
if (b == 0)
return a;
za = __builtin_ctzll(a);
zb = __builtin_ctzll(b);
k = FFMIN(za, zb);
u = llabs(a >> za);
v = llabs(b >> zb);
while (u != v) {
if (u > v)
FFSWAP(int64_t, v, u);
v -= u;
v >>= __builtin_ctzll(v);
}
return (uint64_t)u << k;
}
int mp42_reduce(int *dst_num, int *dst_den,
int64_t num, int64_t den, int64_t max)
{
MP42Rational a0 = { 0, 1 }, a1 = { 1, 0 };
int sign = (num < 0) ^ (den < 0);
int64_t gcd = mp42_gcd(FFABS(num), FFABS(den));
if (gcd) {
num = FFABS(num) / gcd;
den = FFABS(den) / gcd;
}
if (num <= max && den <= max) {
a1 = make_rational((int)num, (int)den);
den = 0;
}
while (den) {
uint64_t x = num / den;
int64_t next_den = num - den * x;
int64_t a2n = x * a1.num + a0.num;
int64_t a2d = x * a1.den + a0.den;
if (a2n > max || a2d > max) {
if (a1.num) x = (max - a0.num) / a1.num;
if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den);
if (den * (2 * x * a1.den + a0.den) > num * a1.den)
a1 = make_rational((int)(x * a1.num + a0.num),(int)(x * a1.den + a0.den));
break;
}
a0 = a1;
a1 = make_rational((int)a2n, (int)a2d);
num = den;
den = next_den;
}
*dst_num = sign ? -a1.num : a1.num;
*dst_den = a1.den;
return den == 0;
}
MP42Rational mp42_d2q(double d, int max)
{
MP42Rational a;
int exponent;
int64_t den;
if (isnan(d))
return make_rational(0,0);
if (fabs(d) > INT_MAX + 3LL)
return make_rational(d < 0 ? -1 : 1, 0);
frexp(d, &exponent);
exponent = FFMAX(exponent-1, 0);
den = 1LL << (61 - exponent);
mp42_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);
if ((!a.num || !a.den) && d && max>0 && max<INT_MAX)
mp42_reduce(&a.num, &a.den, floor(d * den + 0.5), den, INT_MAX);
return a;
}
enum MP42Rounding {
MP42_ROUND_ZERO = 0, ///< Round toward zero.
MP42_ROUND_INF = 1, ///< Round away from zero.
MP42_ROUND_DOWN = 2, ///< Round toward -infinity.
MP42_ROUND_UP = 3, ///< Round toward +infinity.
MP42_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
MP42_ROUND_PASS_MINMAX = 8192,
};
int64_t mp42_rescale_rnd(int64_t a, int64_t b, int64_t c, enum MP42Rounding rnd)
{
int64_t r = 0;
if (c <= 0 || b < 0 || !((unsigned)(rnd&~MP42_ROUND_PASS_MINMAX)<=5 && (rnd&~MP42_ROUND_PASS_MINMAX)!=4))
return INT64_MIN;
if (rnd & MP42_ROUND_PASS_MINMAX) {
if (a == INT64_MIN || a == INT64_MAX)
return a;
rnd -= MP42_ROUND_PASS_MINMAX;
}
if (a < 0)
return -(uint64_t)mp42_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, rnd ^ ((rnd >> 1) & 1));
if (rnd == MP42_ROUND_NEAR_INF)
r = c / 2;
else if (rnd & 1)
r = c - 1;
if (b <= INT_MAX && c <= INT_MAX) {
if (a <= INT_MAX)
return (a * b + r) / c;
else {
int64_t ad = a / c;
int64_t a2 = (a % c * b + r) / c;
if (ad >= INT32_MAX && b && ad > (INT64_MAX - a2) / b)
return INT64_MIN;
return ad * b + a2;
}
} else {
uint64_t a0 = a & 0xFFFFFFFF;
uint64_t a1 = a >> 32;
uint64_t b0 = b & 0xFFFFFFFF;
uint64_t b1 = b >> 32;
uint64_t t1 = a0 * b1 + a1 * b0;
uint64_t t1a = t1 << 32;
int i;
a0 = a0 * b0 + t1a;
a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a);
a0 += r;
a1 += a0 < r;
for (i = 63; i >= 0; i--) {
a1 += a1 + ((a0 >> i) & 1);
t1 += t1;
if (c <= a1) {
a1 -= c;
t1++;
}
}
if (t1 > INT64_MAX)
return INT64_MIN;
return t1;
}
}
int64_t mp42_rescale(int64_t a, int64_t b, int64_t c)
{
return mp42_rescale_rnd(a, b, c, MP42_ROUND_NEAR_INF);
}
+35
View File
@@ -0,0 +1,35 @@
//
// MP42Rational.h
// MP42Foundation
//
// Created by Damiano Galassi on 28/05/21.
//
#ifndef MP42Rational_h
#define MP42Rational_h
#include <stdio.h>
typedef struct MP42Rational {
int32_t num;
int32_t den;
} MP42Rational;
static inline MP42Rational make_rational(int32_t num, int32_t den) {
MP42Rational r = { num, den };
return r;
}
static inline double mp42_q2d(MP42Rational a) {
return a.num / (double) a.den;
}
MP42Rational mp42_d2q(double d, int max);
int64_t mp42_rescale(int64_t a, int64_t b, int64_t c);
static inline int64_t mp42_rescale_q(MP42Rational q, int b)
{
return mp42_rescale(q.num, b, q.den);
}
#endif /* MP42Rational_h */
+5
View File
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import <MP42Foundation/MP42Track.h>
#import <MP42Foundation/MP42MasteringDisplayMetadata.h>
@interface MP42VideoTrack : MP42Track <NSSecureCoding, NSCopying>
@@ -25,6 +26,10 @@
@property(nonatomic, readwrite) uint16_t matrixCoefficients;
@property(nonatomic, readwrite) uint16_t colorRange;
// HDR Mastering Metadata
@property(nonatomic, readwrite) MP42MasteringDisplayMetadata mastering;
@property(nonatomic, readwrite) MP42ContentLightMetadata coll;
// Pixel Aspect Ratio
@property(nonatomic, readwrite) uint64_t hSpacing;
@property(nonatomic, readwrite) uint64_t vSpacing;
+184 -36
View File
@@ -78,6 +78,53 @@ MP42_OBJC_DIRECT_MEMBERS
}
}
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clli")) {
uint64_t maxCLL, maxFALL;
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clli.maxContentLightLevel", &maxCLL);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clli.maxPicAverageLightLevel", &maxFALL);
_coll.MaxCLL = (unsigned int)maxCLL;
_coll.MaxFALL = (unsigned int)maxFALL;
}
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv")) {
uint64_t displayPrimariesGX, displayPrimariesGY, displayPrimariesBX,
displayPrimariesBY, displayPrimariesRX, displayPrimariesRY,
whitePointX, whitePointY,
maxDisplayMasteringLuminance, minDisplayMasteringLuminance;
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesGX", &displayPrimariesGX);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesGY", &displayPrimariesGY);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesBX", &displayPrimariesBX);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesBY", &displayPrimariesBY);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesRX", &displayPrimariesRX);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.displayPrimariesRY", &displayPrimariesRY);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.whitePointX", &whitePointX);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.whitePointY", &whitePointY);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.maxDisplayMasteringLuminance", &maxDisplayMasteringLuminance);
MP4GetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.mdcv.minDisplayMasteringLuminance", &minDisplayMasteringLuminance);
const int chromaDen = 50000;
const int lumaDen = 10000;
_mastering.display_primaries[0][0] = make_rational((int)displayPrimariesRX, chromaDen);
_mastering.display_primaries[0][1] = make_rational((int)displayPrimariesRY, chromaDen);
_mastering.display_primaries[1][0] = make_rational((int)displayPrimariesGX, chromaDen);
_mastering.display_primaries[1][1] = make_rational((int)displayPrimariesGY, chromaDen);
_mastering.display_primaries[2][0] = make_rational((int)displayPrimariesBX, chromaDen);
_mastering.display_primaries[2][1] = make_rational((int)displayPrimariesBY, chromaDen);
_mastering.white_point[0] = make_rational((int)whitePointX, chromaDen);
_mastering.white_point[1] = make_rational((int)whitePointY, chromaDen);
_mastering.max_luminance = make_rational((int)maxDisplayMasteringLuminance, lumaDen);
_mastering.min_luminance = make_rational((int)minDisplayMasteringLuminance, lumaDen);
_mastering.has_primaries = 1;
_mastering.has_luminance = 1;
}
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);
@@ -140,10 +187,10 @@ static uint32_t convertToFixedPoint(CGFloat value) {
uint8_t *val;
uint8_t nval[36];
uint32_t *ptr32 = (uint32_t *) nval;
uint32_t *ptr32 = (uint32_t *)nval;
uint32_t size;
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
MP4GetTrackBytesProperty(fileHandle, self.trackId, "tkhd.matrix", &val, &size);
memcpy(nval, val, size);
ptr32[0] = convertToFixedPoint(_transform.a);
ptr32[1] = convertToFixedPoint(_transform.b);
@@ -155,22 +202,10 @@ static uint32_t convertToFixedPoint(CGFloat value) {
free(val);
if (self.updatedProperty[@"hSpacing"] || self.updatedProperty[@"vSpacing"]) {
if (_hSpacing >= 1 && _vSpacing >= 1) {
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp")) {
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", _hSpacing);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", _vSpacing);
}
else {
MP4AddPixelAspectRatio(fileHandle, self.trackId, (uint32_t)_hSpacing, (uint32_t)_vSpacing);
}
}
}
if (self.updatedProperty[@"colr"] &&
(self.format == kMP42VideoCodecType_H264 || self.format == kMP42VideoCodecType_MPEG4Video
if ((self.format == kMP42VideoCodecType_H264 || self.format == kMP42VideoCodecType_MPEG4Video
|| self.format == kMP42VideoCodecType_HEVC || self.format == kMP42VideoCodecType_HEVC_PSinBitstream)) {
if (self.updatedProperty[@"colr"] || self.muxed == NO) {
if (_colorPrimaries > 0 && _transferCharacteristics > 0 && _matrixCoefficients > 0) {
const char *type;
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.colr")) {
@@ -195,25 +230,69 @@ static uint32_t convertToFixedPoint(CGFloat value) {
}
}
if (_cleanApertureWidthN >= 1 && _cleanApertureHeightN >= 1) {
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap")) {
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", _cleanApertureWidthN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", _cleanApertureWidthD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", _cleanApertureHeightN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", _cleanApertureHeightD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", _horizOffN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", _horizOffD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", _vertOffN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", _vertOffD);
if (self.updatedProperty[@"coll"] || self.muxed == NO) {
if (self.coll.MaxCLL > 0 && self.coll.MaxFALL > 0) {
MP4SetContentLightMetadata(fileHandle, self.trackId, _coll.MaxCLL, _coll.MaxFALL);
}
else {
MP4SetContentLightMetadata(fileHandle, self.trackId, 0, 0);
}
}
if (self.updatedProperty[@"mdcv"] || self.muxed == NO) {
if (self.mastering.has_primaries && self.mastering.has_luminance) {
const int chromaDen = 50000;
const int lumaDen = 10000;
MP4SetMasteringDisplayMetadata(fileHandle, self.trackId,
mp42_rescale_q(_mastering.display_primaries[1][0], chromaDen),
mp42_rescale_q(_mastering.display_primaries[1][1], chromaDen),
mp42_rescale_q(_mastering.display_primaries[2][0], chromaDen),
mp42_rescale_q(_mastering.display_primaries[2][1], chromaDen),
mp42_rescale_q(_mastering.display_primaries[0][0], chromaDen),
mp42_rescale_q(_mastering.display_primaries[0][1], chromaDen),
mp42_rescale_q(_mastering.white_point[0], chromaDen),
mp42_rescale_q(_mastering.white_point[1], chromaDen),
(uint32_t)mp42_rescale_q(_mastering.max_luminance, lumaDen),
(uint32_t)mp42_rescale_q(_mastering.min_luminance, lumaDen));
}
else {
MP4SetMasteringDisplayMetadata(fileHandle, self.trackId, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
}
if (self.updatedProperty[@"hSpacing"] || self.updatedProperty[@"vSpacing"] || self.muxed == NO) {
if (_hSpacing >= 1 && _vSpacing >= 1) {
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp")) {
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp.hSpacing", _hSpacing);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp.vSpacing", _vSpacing);
}
else {
MP4AddPixelAspectRatio(fileHandle, self.trackId, (uint32_t)_hSpacing, (uint32_t)_vSpacing);
}
}
}
if (_cleanApertureWidthN >= 1 && _cleanApertureHeightN >= 1) {
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap")) {
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthN", _cleanApertureWidthN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureWidthD", _cleanApertureWidthD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightN", _cleanApertureHeightN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.cleanApertureHeightD", _cleanApertureHeightD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.horizOffN", _horizOffN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.horizOffD", _horizOffD);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.vertOffN", _vertOffN);
MP4SetTrackIntegerProperty(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.clap.vertOffD", _vertOffD);
}
else {
MP4AddCleanAperture(fileHandle, self.trackId,
(uint32_t)_cleanApertureWidthN, (uint32_t)_cleanApertureWidthD,
(uint32_t)_cleanApertureHeightN, (uint32_t)_cleanApertureHeightD,
(uint32_t)_horizOffN, (uint32_t)_horizOffD, (uint32_t)_vertOffN, (uint32_t)_vertOffD);
}
}
else
MP4AddCleanAperture(fileHandle, self.trackId,
(uint32_t)_cleanApertureWidthN, (uint32_t)_cleanApertureWidthD,
(uint32_t)_cleanApertureHeightN, (uint32_t)_cleanApertureHeightD,
(uint32_t)_horizOffN, (uint32_t)_horizOffD, (uint32_t)_vertOffN, (uint32_t)_vertOffD);
}
if (self.format == kMP42VideoCodecType_H264) {
@@ -277,6 +356,20 @@ static uint32_t convertToFixedPoint(CGFloat value) {
self.edited = YES;
}
- (void)setMastering:(MP42MasteringDisplayMetadata)mastering
{
self.updatedProperty[@"mdcv"] = @YES;
_mastering = mastering;
self.edited = YES;
}
- (void)setColl:(MP42ContentLightMetadata)coll
{
self.updatedProperty[@"coll"] = @YES;
_coll = coll;
self.edited = YES;
}
- (void)setHSpacing:(uint64_t)newHSpacing
{
_hSpacing = newHSpacing;
@@ -336,6 +429,9 @@ static uint32_t convertToFixedPoint(CGFloat value) {
copy->_matrixCoefficients = _matrixCoefficients;
copy->_colorRange = _colorRange;
copy->_mastering = _mastering;
copy->_coll = _coll;
copy->_hSpacing = _hSpacing;
copy->_vSpacing = _vSpacing;
@@ -379,7 +475,33 @@ static uint32_t convertToFixedPoint(CGFloat value) {
[coder encodeInt32:_colorPrimaries forKey:@"colorPrimaries"];
[coder encodeInt32:_transferCharacteristics forKey:@"transferCharacteristics"];
[coder encodeInt32:_matrixCoefficients forKey:@"matrixCoefficients"];
[coder encodeInt32:_colorRange forKey:@"coloRange"];
[coder encodeInt32:_colorRange forKey:@"colorRange"];
[coder encodeInt32:_mastering.display_primaries[0][0].num forKey:@"displayPrimaries00Num"];
[coder encodeInt32:_mastering.display_primaries[0][0].den forKey:@"displayPrimaries00Den"];
[coder encodeInt32:_mastering.display_primaries[0][1].num forKey:@"displayPrimaries01Num"];
[coder encodeInt32:_mastering.display_primaries[0][1].den forKey:@"displayPrimaries01Den"];
[coder encodeInt32:_mastering.display_primaries[1][0].num forKey:@"displayPrimaries10Num"];
[coder encodeInt32:_mastering.display_primaries[1][0].den forKey:@"displayPrimaries10Den"];
[coder encodeInt32:_mastering.display_primaries[1][1].num forKey:@"displayPrimaries11Num"];
[coder encodeInt32:_mastering.display_primaries[1][1].den forKey:@"displayPrimaries11Den"];
[coder encodeInt32:_mastering.display_primaries[2][0].num forKey:@"displayPrimaries20Num"];
[coder encodeInt32:_mastering.display_primaries[2][0].den forKey:@"displayPrimaries20Den"];
[coder encodeInt32:_mastering.display_primaries[2][1].num forKey:@"displayPrimaries21Num"];
[coder encodeInt32:_mastering.display_primaries[2][1].den forKey:@"displayPrimaries21Den"];
[coder encodeInt32:_mastering.white_point[0].num forKey:@"whitePoint0Num"];
[coder encodeInt32:_mastering.white_point[0].den forKey:@"whitePoint0Den"];
[coder encodeInt32:_mastering.white_point[1].num forKey:@"whitePoint1Num"];
[coder encodeInt32:_mastering.white_point[1].den forKey:@"whitePoint1Den"];
[coder encodeInt32:_mastering.has_primaries forKey:@"hasPrimaries"];
[coder encodeInt32:_mastering.has_luminance forKey:@"hasLuminance"];
[coder encodeInt64:_coll.MaxCLL forKey:@"maxCLL"];
[coder encodeInt64:_coll.MaxFALL forKey:@"maxFALL"];
[coder encodeInt64:_hSpacing forKey:@"hSpacing"];
[coder encodeInt64:_vSpacing forKey:@"vSpacing"];
@@ -414,6 +536,32 @@ static uint32_t convertToFixedPoint(CGFloat value) {
_matrixCoefficients = (uint16_t)[decoder decodeInt32ForKey:@"matrixCoefficients"];
_colorRange = (uint16_t)[decoder decodeInt32ForKey:@"colorRange"];
_mastering.display_primaries[0][0].num = [decoder decodeInt32ForKey:@"displayPrimaries00Num"];
_mastering.display_primaries[0][0].den = [decoder decodeInt32ForKey:@"displayPrimaries00Den"];
_mastering.display_primaries[0][1].num = [decoder decodeInt32ForKey:@"displayPrimaries01Num"];
_mastering.display_primaries[0][1].den = [decoder decodeInt32ForKey:@"displayPrimaries01Den"];
_mastering.display_primaries[1][0].num = [decoder decodeInt32ForKey:@"displayPrimaries10Num"];
_mastering.display_primaries[1][0].den = [decoder decodeInt32ForKey:@"displayPrimaries10Den"];
_mastering.display_primaries[1][1].num = [decoder decodeInt32ForKey:@"displayPrimaries11Num"];
_mastering.display_primaries[1][1].den = [decoder decodeInt32ForKey:@"displayPrimaries11Den"];
_mastering.display_primaries[2][0].num = [decoder decodeInt32ForKey:@"displayPrimaries20Num"];
_mastering.display_primaries[2][0].den = [decoder decodeInt32ForKey:@"displayPrimaries20Den"];
_mastering.display_primaries[2][1].num = [decoder decodeInt32ForKey:@"displayPrimaries21Num"];
_mastering.display_primaries[2][1].den = [decoder decodeInt32ForKey:@"displayPrimaries21Den"];
_mastering.white_point[0].num = [decoder decodeInt32ForKey:@"whitePoint0Num"];
_mastering.white_point[0].den = [decoder decodeInt32ForKey:@"whitePoint0Den"];
_mastering.white_point[1].num = [decoder decodeInt32ForKey:@"whitePoint1Num"];
_mastering.white_point[1].den = [decoder decodeInt32ForKey:@"whitePoint1Den"];
_mastering.has_primaries = [decoder decodeInt32ForKey:@"hasPrimaries"] > 0;
_mastering.has_luminance = [decoder decodeInt32ForKey:@"hasLuminance"] > 0;
_coll.MaxCLL = (uint32_t)[decoder decodeInt64ForKey:@"maxCLL"];
_coll.MaxFALL = (uint32_t)[decoder decodeInt64ForKey:@"maxFALL"];
_hSpacing = [decoder decodeInt64ForKey:@"hSpacing"];
_vSpacing = [decoder decodeInt64ForKey:@"vSpacing"];
@@ -435,7 +583,7 @@ static uint32_t convertToFixedPoint(CGFloat value) {
}
- (NSString *)description {
return [[super description] stringByAppendingFormat:@", %lld x %lld", _width, _height];
return [super.description stringByAppendingFormat:@", %lld x %lld", _width, _height];
}
@end
+18
View File
@@ -126,6 +126,12 @@
A96523491BAC315900E994E0 /* NSString+MP42Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = A96523441BAC315900E994E0 /* NSString+MP42Additions.m */; };
A96D28931BAD390400403327 /* MP42Metadata+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A96D28921BAD390400403327 /* MP42Metadata+Private.h */; };
A96D28941BAD390400403327 /* MP42Metadata+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A96D28921BAD390400403327 /* MP42Metadata+Private.h */; };
A9762BA82660CF590055E0B3 /* MP42MasteringDisplayMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = A9762BA62660CF590055E0B3 /* MP42MasteringDisplayMetadata.h */; settings = {ATTRIBUTES = (Public, ); }; };
A9762BA92660CF590055E0B3 /* MP42MasteringDisplayMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = A9762BA62660CF590055E0B3 /* MP42MasteringDisplayMetadata.h */; };
A9762BAE2660D71E0055E0B3 /* MP42Rational.h in Headers */ = {isa = PBXBuildFile; fileRef = A9762BAC2660D71E0055E0B3 /* MP42Rational.h */; settings = {ATTRIBUTES = (Public, ); }; };
A9762BAF2660D71E0055E0B3 /* MP42Rational.h in Headers */ = {isa = PBXBuildFile; fileRef = A9762BAC2660D71E0055E0B3 /* MP42Rational.h */; };
A9762BB02660D71E0055E0B3 /* MP42Rational.c in Sources */ = {isa = PBXBuildFile; fileRef = A9762BAD2660D71E0055E0B3 /* MP42Rational.c */; };
A9762BB12660D71E0055E0B3 /* MP42Rational.c in Sources */ = {isa = PBXBuildFile; fileRef = A9762BAD2660D71E0055E0B3 /* MP42Rational.c */; };
A97EA7C71D4B8A2D00257CEA /* FFmpegUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = A97EA7C51D4B8A2D00257CEA /* FFmpegUtils.h */; };
A97EA7C81D4B8A2D00257CEA /* FFmpegUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = A97EA7C51D4B8A2D00257CEA /* FFmpegUtils.h */; };
A97EA7C91D4B8A2D00257CEA /* FFmpegUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = A97EA7C61D4B8A2D00257CEA /* FFmpegUtils.m */; };
@@ -303,6 +309,9 @@
A96523431BAC315900E994E0 /* NSString+MP42Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MP42Additions.h"; sourceTree = "<group>"; };
A96523441BAC315900E994E0 /* NSString+MP42Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MP42Additions.m"; sourceTree = "<group>"; };
A96D28921BAD390400403327 /* MP42Metadata+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MP42Metadata+Private.h"; sourceTree = "<group>"; };
A9762BA62660CF590055E0B3 /* MP42MasteringDisplayMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MP42MasteringDisplayMetadata.h; sourceTree = "<group>"; };
A9762BAC2660D71E0055E0B3 /* MP42Rational.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MP42Rational.h; sourceTree = "<group>"; };
A9762BAD2660D71E0055E0B3 /* MP42Rational.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = MP42Rational.c; sourceTree = "<group>"; };
A97EA7C51D4B8A2D00257CEA /* FFmpegUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FFmpegUtils.h; sourceTree = "<group>"; };
A97EA7C61D4B8A2D00257CEA /* FFmpegUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FFmpegUtils.m; sourceTree = "<group>"; };
A989F10D1823B3B40070AD8C /* MP42TextSample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42TextSample.h; sourceTree = "<group>"; };
@@ -706,6 +715,9 @@
A9ED5B0C1F824A9B00E0E4FA /* MP42SSAParser.m */,
A941C95C1F82A9B800FC5E8D /* MP42SSAConverter.h */,
A941C95D1F82A9B800FC5E8D /* MP42SSAConverter.m */,
A9762BAC2660D71E0055E0B3 /* MP42Rational.h */,
A9762BAD2660D71E0055E0B3 /* MP42Rational.c */,
A9762BA62660CF590055E0B3 /* MP42MasteringDisplayMetadata.h */,
A96523431BAC315900E994E0 /* NSString+MP42Additions.h */,
A96523441BAC315900E994E0 /* NSString+MP42Additions.m */,
A9B5C954241A302E000ACD15 /* SampleCursor.swift */,
@@ -748,11 +760,13 @@
files = (
A941A7B51DA7B08600FB2A7C /* MP42MetadataFormat.h in Headers */,
A930D8E922351E2F0061CF37 /* MP42SecurityAccessToken.h in Headers */,
A9762BA92660CF590055E0B3 /* MP42MasteringDisplayMetadata.h in Headers */,
A97EA7C81D4B8A2D00257CEA /* FFmpegUtils.h in Headers */,
A90801121D4B83A3002B6950 /* MP42AudioDecoder.h in Headers */,
A91C3AD11BF20CF1008BCF87 /* MP42FormatUtilites.h in Headers */,
A96D28941BAD390400403327 /* MP42Metadata+Private.h in Headers */,
A90801161D4B83A3002B6950 /* MP42AudioEncoder.h in Headers */,
A9762BAF2660D71E0055E0B3 /* MP42Rational.h in Headers */,
A9ED5B161F824BC100E0E4FA /* MP42SSAImporter.h in Headers */,
A9422FC81D4917AF000DB435 /* audio_resample.h in Headers */,
A9195F372233DD38005C4D01 /* MP42RelatedItem.h in Headers */,
@@ -792,7 +806,9 @@
A989F10F1823B3B40070AD8C /* MP42TextSample.h in Headers */,
A9B9C2831823923200416A4E /* MP42Image.h in Headers */,
A9B9C2C41823957800416A4E /* MP42Languages.h in Headers */,
A9762BA82660CF590055E0B3 /* MP42MasteringDisplayMetadata.h in Headers */,
A96523451BAC315900E994E0 /* NSString+MP42Additions.h in Headers */,
A9762BAE2660D71E0055E0B3 /* MP42Rational.h in Headers */,
A930D8E822351E2F0061CF37 /* MP42SecurityAccessToken.h in Headers */,
A9195F362233DD38005C4D01 /* MP42RelatedItem.h in Headers */,
A941A7B41DA7B08600FB2A7C /* MP42MetadataFormat.h in Headers */,
@@ -987,6 +1003,7 @@
A9D764321E278B8100ED2F78 /* MP42MetadataUtilities.m in Sources */,
A910B60918394EB20064028F /* MP42Mp4Importer.m in Sources */,
A910B60D18394EB20064028F /* MP42SrtImporter.m in Sources */,
A9762BB12660D71E0055E0B3 /* MP42Rational.c in Sources */,
A9DFBDA5195FF5BA00410060 /* MP42Heap.m in Sources */,
A910B60F18394EB20064028F /* MP42AVFImporter.m in Sources */,
A910B61118394EB20064028F /* MP42CCImporter.m in Sources */,
@@ -1052,6 +1069,7 @@
A9B9C2841823923200416A4E /* MP42Image.m in Sources */,
A9D764311E278B8100ED2F78 /* MP42MetadataUtilities.m in Sources */,
A9B9C29E1823923200416A4E /* MP42PrivateUtilities.m in Sources */,
A9762BB02660D71E0055E0B3 /* MP42Rational.c in Sources */,
A97EA7C91D4B8A2D00257CEA /* FFmpegUtils.m in Sources */,
A91C3ACE1BF20CF1008BCF87 /* MP42FormatUtilites.mm in Sources */,
A9B9C26D1823923200416A4E /* MP42AudioTrack.m in Sources */,