Update to newer libmp4v2, add support for VVC and AV1 Dolby Vision.
This commit is contained in:
14 files changed
+149
-56
No files matched your search
@@ -867,6 +867,9 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
code == kCMVideoCodecType_DolbyVisionHEVC || code == kMP42VideoCodecType_DolbyVisionHEVC_PSinBitstream) {
|
||||
magicCookie = CFDictionaryGetValue(atoms, @"hvcC");
|
||||
}
|
||||
else if (code == kMP42VideoCodecType_VVC || code == kMP42VideoCodecType_VVC_PSinBitstream) {
|
||||
magicCookie = CFDictionaryGetValue(atoms, @"vvcC");
|
||||
}
|
||||
else if (code == kMP42VideoCodecType_AV1) {
|
||||
magicCookie = CFDictionaryGetValue(atoms, @"av1C");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "FFmpegUtils.h"
|
||||
|
||||
@import QuartzCore;
|
||||
@import CoreImage;
|
||||
|
||||
MP42_OBJC_DIRECT_MEMBERS
|
||||
|
||||
+1
-1
@@ -304,7 +304,7 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
MP4Duration duration;
|
||||
MP4Duration renderingOffset;
|
||||
MP4Timestamp pStartTime;
|
||||
bool isSyncSample;
|
||||
unsigned char isSyncSample;
|
||||
|
||||
if (!MP4ReadSample(self.fileHandle,
|
||||
track.trackId,
|
||||
|
||||
@@ -117,11 +117,6 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
return _image;
|
||||
}
|
||||
|
||||
- (NSString *)imageRepresentationType
|
||||
{
|
||||
return IKImageBrowserNSImageRepresentationType;
|
||||
}
|
||||
|
||||
- (NSString *)uuid
|
||||
{
|
||||
@synchronized(self) {
|
||||
|
||||
+18
-2
@@ -239,6 +239,22 @@ typedef struct MP4DemuxHelper {
|
||||
free(ppValue);
|
||||
return magicCookie;
|
||||
}
|
||||
else if (!strcmp(media_data_name, "vvc1")) {
|
||||
uint8_t *ppValue;
|
||||
uint32_t pValueSize;
|
||||
MP4GetTrackBytesProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.vvc1.vvcC.content", &ppValue, &pValueSize);
|
||||
magicCookie = [NSData dataWithBytes:ppValue length:pValueSize];
|
||||
free(ppValue);
|
||||
return magicCookie;
|
||||
}
|
||||
else if (!strcmp(media_data_name, "vvic")) {
|
||||
uint8_t *ppValue;
|
||||
uint32_t pValueSize;
|
||||
MP4GetTrackBytesProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.vvic.vvcC.content", &ppValue, &pValueSize);
|
||||
magicCookie = [NSData dataWithBytes:ppValue length:pValueSize];
|
||||
free(ppValue);
|
||||
return magicCookie;
|
||||
}
|
||||
else if (!strcmp(media_data_name, "av01")) {
|
||||
uint8_t *ppValue;
|
||||
uint32_t pValueSize;
|
||||
@@ -352,8 +368,8 @@ typedef struct MP4DemuxHelper {
|
||||
MP4Duration duration;
|
||||
MP4Duration renderingOffset;
|
||||
MP4Timestamp pStartTime;
|
||||
bool isSyncSample;
|
||||
bool hasDependencyFlags;
|
||||
unsigned char isSyncSample;
|
||||
unsigned char hasDependencyFlags;
|
||||
uint32_t dependencyFlags;
|
||||
|
||||
demuxHelper->currentSampleId = demuxHelper->currentSampleId + 1;
|
||||
|
||||
+71
-4
@@ -270,7 +270,7 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
force_HEVC_completeness(hvcCAtom, (uint32_t)magicCookie.length);
|
||||
}
|
||||
|
||||
bool completeness = 0;
|
||||
bool completeness = false;
|
||||
if (magicCookie.length && magicCookie.length < UINT32_MAX && !analyze_HEVC(magicCookie.bytes, (uint32_t)magicCookie.length, &completeness)) {
|
||||
|
||||
dstTrackId = MP4AddDolbyVisionH265VideoTrack(_fileHandle, timeScale, MP4_INVALID_DURATION,
|
||||
@@ -305,6 +305,56 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
}
|
||||
}
|
||||
|
||||
// H.266 video track
|
||||
else if ([track isMemberOfClass:[MP42VideoTrack class]] &&
|
||||
(format == kMP42VideoCodecType_VVC || format == kMP42VideoCodecType_VVC_PSinBitstream)) {
|
||||
|
||||
MP42VideoTrack *videoTrack = (MP42VideoTrack *)track;
|
||||
// uint8_t *vvcCAtom = (uint8_t *)magicCookie.bytes;
|
||||
|
||||
// if ([_options[MP42ForceHvc1] boolValue] && magicCookie.length < UINT32_MAX) {
|
||||
// force_HEVC_completeness(hvcCAtom, (uint32_t)magicCookie.length);
|
||||
// }
|
||||
|
||||
// Check whether we can use hvc1 or hev1 fourcc.
|
||||
bool completeness = true;
|
||||
if (magicCookie.length && magicCookie.length < UINT32_MAX && !analyze_HEVC(magicCookie.bytes, (uint32_t)magicCookie.length, &completeness)) {
|
||||
|
||||
dstTrackId = MP4AddVVCVideoTrack(_fileHandle, timeScale, MP4_INVALID_DURATION,
|
||||
videoTrack.width, videoTrack.height,
|
||||
magicCookie.bytes, (uint32_t)magicCookie.length,
|
||||
completeness);
|
||||
|
||||
if (dstTrackId) {
|
||||
if (videoTrack.dolbyVision.versionMajor > 0) {
|
||||
MP4SetDolbyVisionMetadata(_fileHandle, dstTrackId,
|
||||
videoTrack.dolbyVision.versionMajor,
|
||||
videoTrack.dolbyVision.versionMinor,
|
||||
videoTrack.dolbyVision.profile,
|
||||
videoTrack.dolbyVision.level,
|
||||
videoTrack.dolbyVision.rpuPresentFlag,
|
||||
videoTrack.dolbyVision.elPresentFlag,
|
||||
videoTrack.dolbyVision.blPresentFlag,
|
||||
videoTrack.dolbyVision.blSignalCompatibilityId);
|
||||
}
|
||||
if (videoTrack.dolbyVisionELConfiguration) {
|
||||
MP4SetDolbyVisionELConfiguration(_fileHandle, dstTrackId,
|
||||
videoTrack.dolbyVisionELConfiguration.bytes,
|
||||
(uint32_t)videoTrack.dolbyVisionELConfiguration.length);
|
||||
}
|
||||
[importer setActiveTrack:track];
|
||||
}
|
||||
else {
|
||||
[unsupportedTracks addObject:track];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
[unsupportedTracks addObject:track];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// AV1 video track
|
||||
else if ([track isMemberOfClass:[MP42VideoTrack class]] && (format == kMP42VideoCodecType_AV1)) {
|
||||
MP42VideoTrack *videoTrack = (MP42VideoTrack *)track;
|
||||
@@ -315,6 +365,22 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
magicCookie.bytes, (uint32_t)magicCookie.length);
|
||||
|
||||
if (dstTrackId) {
|
||||
if (videoTrack.dolbyVision.versionMajor > 0) {
|
||||
MP4SetDolbyVisionMetadata(_fileHandle, dstTrackId,
|
||||
videoTrack.dolbyVision.versionMajor,
|
||||
videoTrack.dolbyVision.versionMinor,
|
||||
videoTrack.dolbyVision.profile,
|
||||
videoTrack.dolbyVision.level,
|
||||
videoTrack.dolbyVision.rpuPresentFlag,
|
||||
videoTrack.dolbyVision.elPresentFlag,
|
||||
videoTrack.dolbyVision.blPresentFlag,
|
||||
videoTrack.dolbyVision.blSignalCompatibilityId);
|
||||
}
|
||||
if (videoTrack.dolbyVisionELConfiguration) {
|
||||
MP4SetDolbyVisionELConfiguration(_fileHandle, dstTrackId,
|
||||
videoTrack.dolbyVisionELConfiguration.bytes,
|
||||
(uint32_t)videoTrack.dolbyVisionELConfiguration.length);
|
||||
}
|
||||
[importer setActiveTrack:track];
|
||||
}
|
||||
else {
|
||||
@@ -649,13 +715,14 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
bool err = false;
|
||||
if (sampleBuffer->dependecyFlags) {
|
||||
err = MP4WriteSampleDependency(_fileHandle, trackId, sampleBuffer->data, sampleBuffer->size,
|
||||
sampleBuffer->duration, sampleBuffer->offset,
|
||||
sampleBuffer->flags & MP42SampleBufferFlagIsSync, sampleBuffer->dependecyFlags);
|
||||
sampleBuffer->duration, sampleBuffer->offset,
|
||||
(sampleBuffer->flags & MP42SampleBufferFlagIsSync) != 0,
|
||||
sampleBuffer->dependecyFlags);
|
||||
} else {
|
||||
err = MP4WriteSample(_fileHandle, trackId,
|
||||
sampleBuffer->data, sampleBuffer->size,
|
||||
sampleBuffer->duration, sampleBuffer->offset,
|
||||
sampleBuffer->flags & MP42SampleBufferFlagIsSync);
|
||||
(sampleBuffer->flags & MP42SampleBufferFlagIsSync) != 0);
|
||||
}
|
||||
if (!err) {
|
||||
_cancelled = YES;
|
||||
|
||||
@@ -242,7 +242,7 @@ static void insertTagsFromStyleRecord(style_record record, NSMutableString *samp
|
||||
MP4Duration sampleDuration;
|
||||
MP4Duration renderingOffset;
|
||||
MP4Timestamp pStartTime;
|
||||
bool isSyncSample;
|
||||
unsigned char isSyncSample;
|
||||
BOOL forced = NO;
|
||||
BOOL tbox = NO;
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ MP42Duration TimeFromString(NSString *time_string, int32_t timeScale)
|
||||
BOOL isTrackMuxable(FourCharCode format)
|
||||
{
|
||||
FourCharCode supportedFormats[] = {kMP42VideoCodecType_AV1,
|
||||
kMP42VideoCodecType_VVC,
|
||||
kMP42VideoCodecType_VVC_PSinBitstream,
|
||||
kMP42VideoCodecType_HEVC,
|
||||
kMP42VideoCodecType_HEVC_PSinBitstream,
|
||||
kMP42VideoCodecType_DolbyVisionHEVC,
|
||||
|
||||
@@ -308,6 +308,7 @@ static uint32_t convertToFixedPoint(CGFloat value) {
|
||||
|
||||
if ((self.format == kMP42VideoCodecType_H264 || self.format == kMP42VideoCodecType_MPEG4Video
|
||||
|| self.format == kMP42VideoCodecType_HEVC || self.format == kMP42VideoCodecType_HEVC_PSinBitstream
|
||||
|| self.format == kMP42VideoCodecType_VVC || self.format == kMP42VideoCodecType_VVC_PSinBitstream
|
||||
|| self.format == kMP42VideoCodecType_AV1)) {
|
||||
|
||||
if (self.updatedProperty[@"colr"] || self.muxed == NO) {
|
||||
@@ -367,11 +368,11 @@ static uint32_t convertToFixedPoint(CGFloat value) {
|
||||
|
||||
if (self.updatedProperty[@"amve"] || self.muxed == NO) {
|
||||
if (self.ambient.ambient_illuminance && self.ambient.ambient_light_x && self.ambient.ambient_light_y) {
|
||||
MP4SetAmbientViewingEnviroment(fileHandle, self.trackId,
|
||||
_ambient.ambient_illuminance, _ambient.ambient_light_x, _ambient.ambient_light_y);
|
||||
MP4SetAmbientViewingEnvironment(fileHandle, self.trackId,
|
||||
_ambient.ambient_illuminance, _ambient.ambient_light_x, _ambient.ambient_light_y);
|
||||
}
|
||||
else {
|
||||
MP4SetAmbientViewingEnviroment(fileHandle, self.trackId, 0, 0, 0);
|
||||
MP4SetAmbientViewingEnvironment(fileHandle, self.trackId, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import mp4v2
|
||||
import CMP42
|
||||
|
||||
private struct Edit {
|
||||
/// The media start time of the edit segment in track time scale units of the track in the mp4 file.
|
||||
@@ -130,7 +130,7 @@ private struct Edit {
|
||||
|
||||
private func resetMediaTime() {
|
||||
let edit = edits[currentEdit]
|
||||
currentSampleId = MP4GetSampleIdFromTime(fileHandle, trackId, edit.mediaStart, false)
|
||||
currentSampleId = MP4GetSampleIdFromTime(fileHandle, trackId, edit.mediaStart, 0)
|
||||
let time = MP4GetSampleTime(fileHandle, trackId, currentSampleId)
|
||||
currentSampleId -= 1
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import mp4v2
|
||||
import CMP42
|
||||
|
||||
@objc(MP42SampleDescription) public class SampleDescription: NSObject {
|
||||
let format: MP42CodecType
|
||||
@@ -105,7 +105,7 @@ struct H264Profile {
|
||||
|
||||
var hSpacing: UInt64 = 1, vSpacing: UInt64 = 1
|
||||
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].pasp") {
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].pasp") != 0 {
|
||||
MP4GetTrackIntegerProperty(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].pasp.hSpacing", &hSpacing)
|
||||
MP4GetTrackIntegerProperty(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].pasp.vSpacing", &vSpacing)
|
||||
}
|
||||
@@ -114,7 +114,7 @@ struct H264Profile {
|
||||
|
||||
// Content light level
|
||||
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].clli") {
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].clli") != 0 {
|
||||
var maxCLL: UInt64 = 0, maxFALL: UInt64 = 0
|
||||
|
||||
MP4GetTrackIntegerProperty(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].clli.maxContentLightLevel", &maxCLL)
|
||||
@@ -125,7 +125,7 @@ struct H264Profile {
|
||||
|
||||
// Mastering display metadata
|
||||
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].mdcv") {
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].mdcv") != 0 {
|
||||
var displayPrimariesGX: UInt64 = 0, displayPrimariesGY: UInt64 = 0, displayPrimariesBX: UInt64 = 0,
|
||||
displayPrimariesBY: UInt64 = 0, displayPrimariesRX: UInt64 = 0, displayPrimariesRY: UInt64 = 0,
|
||||
whitePointX: UInt64 = 0, whitePointY: UInt64 = 0,
|
||||
@@ -162,7 +162,7 @@ struct H264Profile {
|
||||
|
||||
// Dolby Vision Configuration
|
||||
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].dvcC") {
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].dvcC") != 0 {
|
||||
var versionMajor: UInt64 = 0, versionMinor: UInt64 = 0, profile: UInt64 = 0,
|
||||
level: UInt64 = 0, rpuPresentFlag: UInt64 = 0, elPresentFlag: UInt64 = 0,
|
||||
blPresentFlag: UInt64 = 0, blSignalCompatibilityId: UInt64 = 0;
|
||||
@@ -183,7 +183,7 @@ struct H264Profile {
|
||||
}
|
||||
|
||||
// Clean aperture
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].clap") {
|
||||
if MP4HaveTrackAtom(fileHandle, trackId, "mdia.minf.stbl.stsd.[\(index)].clap") != 0 {
|
||||
var widthN: UInt64 = 0, widthD: UInt64 = 0,
|
||||
heightN: UInt64 = 0, heightD: UInt64 = 0,
|
||||
horizOffN: UInt64 = 0, horizOffD: UInt64 = 0,
|
||||
|
||||
Reference in new issue
Block a user