From abdcc0836996f27702dafca2f9399906ed6399dc Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 15 Jun 2017 17:41:59 +0200 Subject: [PATCH] Preliminary work to read opus a flac thru AVFoundation --- MP42/FFmpegUtils.m | 2 +- MP42/MP42AVFImporter.m | 38 +++++++++++++++++++++++++++++++++++++- MP42/MP42MediaFormat.h | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/MP42/FFmpegUtils.m b/MP42/FFmpegUtils.m index aaa0499..bc693b1 100644 --- a/MP42/FFmpegUtils.m +++ b/MP42/FFmpegUtils.m @@ -106,7 +106,7 @@ static const struct { { kAudioFormatEnhancedAC3, AV_CODEC_ID_EAC3 }, { 'XiFL', AV_CODEC_ID_FLAC }, { 'XiVs', AV_CODEC_ID_VORBIS }, - { 'Opus', AV_CODEC_ID_OPUS }, + { 'opus', AV_CODEC_ID_OPUS }, { kAudioFormatAppleLossless, AV_CODEC_ID_ALAC }, { 'DTS ', AV_CODEC_ID_DTS }, { 'trhd', AV_CODEC_ID_TRUEHD }, diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 24aa838..225cd8e 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -50,7 +50,7 @@ + (NSArray *)supportedFileFormats { return @[@"mov", @"qt", @"mp4", @"m4v", @"m4a", @"mp3", @"m2ts", @"ts", @"mts", - @"ac3", @"eac3", @"ec3", @"webvtt", @"vtt", @"caf", @"aif", @"aiff", @"aifc", @"wav"]; + @"ac3", @"eac3", @"ec3", @"webvtt", @"vtt", @"caf", @"aif", @"aiff", @"aifc", @"wav", @"flac"]; } - (FourCharCode)formatForTrack:(AVAssetTrack *)track { @@ -63,6 +63,9 @@ case 'ms \0': result = kMP42AudioCodecType_AC3; break; + case 'flac': + result = kMP42AudioCodecType_FLAC; + break; case 'SRT ': result = kMP42SubtitleCodecType_Text; break; @@ -206,9 +209,15 @@ else if (CFEqual(transferFunctions, kCMFormatDescriptionTransferFunction_SMPTE_240M_1995)) { videoTrack.transferCharacteristics = 7; } + else if (CFEqual(transferFunctions, CFSTR("SMPTE_ST_2084_PQ"))) { // kCMFormatDescriptionTransferFunction_SMPTE_ST_2084_PQ + videoTrack.transferCharacteristics = 16; + } else if (CFEqual(transferFunctions, kCMFormatDescriptionTransferFunction_SMPTE_ST_428_1)) { videoTrack.transferCharacteristics = 17; } + else if (CFEqual(transferFunctions, CFSTR("ITU_R_2100_HLG"))) { // kCMFormatDescriptionTransferFunction_ITU_R_2100_HLG + videoTrack.transferCharacteristics = 18; + } } CFStringRef YCbCrMatrix = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_YCbCrMatrix); @@ -749,6 +758,33 @@ return [NSData dataWithBytes:cookieBuffer length:cookieSizeOut]; } + else if (code == 'opus') { + // dec3 atom + // remove the atom header + //cookieBuffer += 9; + //cookieSizeOut = cookieSizeOut - 9; + + UInt32 *cookie = (UInt32 *)cookieBuffer; + + for (size_t i = 0; i < cookieSizeOut / 8; i++) { + cookie[i] = EndianS32_BtoN(cookie[i]); + } + + return [NSData dataWithBytes:cookieBuffer length:cookieSizeOut]; + } + + else if (code == 'flac') { + + UInt32 *cookie = (UInt32 *)cookieBuffer; + + for (size_t i = 0; i < cookieSizeOut / 8; i++) { + cookie[i] = EndianS32_BtoN(cookie[i]); + } + + return [NSData dataWithBytes:cookieBuffer length:cookieSizeOut]; + + } + else if (code == kAudioFormatEnhancedAC3) { // dec3 atom // remove the atom header diff --git a/MP42/MP42MediaFormat.h b/MP42/MP42MediaFormat.h index 6299390..7e0b72a 100644 --- a/MP42/MP42MediaFormat.h +++ b/MP42/MP42MediaFormat.h @@ -150,7 +150,7 @@ enum : MP42AudioCodecType kMP42AudioCodecType_DTS = 'DTS ', kMP42AudioCodecType_TrueHD = 'trhd', kMP42AudioCodecType_MLP = 'mlp ', - kMP42AudioCodecType_Opus = 'Opus', + kMP42AudioCodecType_Opus = 'opus', kMP42AudioCodecType_TTA = 'TTA1', kMP42AudioCodecType_FairPlay = 'drms',