From 13102025920d0a7fb113fdaa2fb3a03b2de9ce43 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 13 Aug 2016 13:40:09 +0200 Subject: [PATCH] Implements the localised media names. --- MP42/MP42AudioTrack.m | 7 +- MP42/MP42ChapterTrack.m | 10 - MP42/MP42ClosedCaptionTrack.m | 7 - MP42/MP42MediaFormat.h | 21 +- MP42/MP42MediaFormat.m | 432 ++++++++++++++++++++++++++++------ MP42/MP42MkvImporter.m | 139 +++++------ MP42/MP42Muxer.m | 3 +- MP42/MP42PrivateUtilities.h | 2 +- MP42/MP42PrivateUtilities.m | 28 +-- MP42/MP42SubtitleTrack.m | 5 - MP42/MP42Track.m | 29 +-- MP42/MP42Utilities.m | 37 +-- MP42/MP42VideoTrack.m | 5 - 13 files changed, 486 insertions(+), 239 deletions(-) diff --git a/MP42/MP42AudioTrack.m b/MP42/MP42AudioTrack.m index 15dbb4c..01aa92d 100644 --- a/MP42/MP42AudioTrack.m +++ b/MP42/MP42AudioTrack.m @@ -119,7 +119,6 @@ extern u_int8_t MP4AV_AacConfigGetChannels(u_int8_t* pConfig); { if ((self = [super init])) { - _name = [self defaultName]; _language = @"Unknown"; _volume = 1; _mixdownType = SBDolbyPlIIMixdown; @@ -198,10 +197,6 @@ extern u_int8_t MP4AV_AacConfigGetChannels(u_int8_t* pConfig); return (_trackId > 0); } -- (NSString *)defaultName { - return @"Sound Track"; -} - - (void)dealloc { [_mixdownType release]; @@ -249,7 +244,7 @@ extern u_int8_t MP4AV_AacConfigGetChannels(u_int8_t* pConfig); - (NSString *)formatSummary { - return [NSString stringWithFormat:@"%@, %u ch", @(FourCC2Str(_format)), (unsigned int)_channels]; + return [NSString stringWithFormat:@"%@, %u ch", localizedDisplayName(_mediaType, _format), (unsigned int)_channels]; } - (NSString *)description { diff --git a/MP42/MP42ChapterTrack.m b/MP42/MP42ChapterTrack.m index 8d95afa..fbdb23d 100644 --- a/MP42/MP42ChapterTrack.m +++ b/MP42/MP42ChapterTrack.m @@ -21,7 +21,6 @@ - (instancetype)init { if ((self = [super init])) { - _name = [self defaultName]; _format = kMP42SubtitleCodecType_Text; _language = @"English"; _isEdited = NO; @@ -41,10 +40,6 @@ if (self) { - if (!_name || [_name isEqualToString:@"Text Track"]) { - _name = [self defaultName]; - } - if (!_format) { _format = kMP42SubtitleCodecType_Text; } @@ -86,7 +81,6 @@ - (instancetype)initWithTextFile:(NSURL *)URL { if ((self = [super init])) { - _name = [self defaultName]; _format = kMP42SubtitleCodecType_Text; _sourceURL = [URL retain]; _language = @"English"; @@ -286,10 +280,6 @@ return [file writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:error]; } -- (NSString *)defaultName { - return @"Chapter Track"; -} - - (BOOL)updateFromCSVFile:(NSURL *)URL error:(NSError **)outError { NSArray *csvData = [NSArray arrayWithContentsOfCSVURL:URL]; if (csvData.count == self.chapterCount) { diff --git a/MP42/MP42ClosedCaptionTrack.m b/MP42/MP42ClosedCaptionTrack.m index b5e78f5..2e6ab21 100644 --- a/MP42/MP42ClosedCaptionTrack.m +++ b/MP42/MP42ClosedCaptionTrack.m @@ -26,7 +26,6 @@ - (instancetype)init { if ((self = [super init])) { - _name = [self defaultName]; _format = kMP42ClosedCaptionCodecType_CEA608; _mediaType = kMP42MediaType_ClosedCaption; } @@ -45,12 +44,6 @@ return (_trackId > 0); } -- (NSString *)defaultName { - // TODO - return @"Closed Caption"; - //return kMP42MediaType_ClosedCaption; -} - - (void)dealloc { [super dealloc]; diff --git a/MP42/MP42MediaFormat.h b/MP42/MP42MediaFormat.h index adb57b9..fe769ec 100644 --- a/MP42/MP42MediaFormat.h +++ b/MP42/MP42MediaFormat.h @@ -20,6 +20,9 @@ extern NSString *const MP42FileTypeM4A; extern NSString *const MP42FileTypeM4B; extern NSString *const MP42FileTypeM4R; +NSString *localizedMediaDisplayName(FourCharCode mediaType); +NSString *localizedDisplayName(FourCharCode mediaType, FourCharCode mediaSubtype); + #include #if TARGET_RT_BIG_ENDIAN # define FourCC2Str(fourcc) (const char[]){*((char*)&fourcc), *(((char*)&fourcc)+1), *(((char*)&fourcc)+2), *(((char*)&fourcc)+3),0} @@ -27,7 +30,13 @@ extern NSString *const MP42FileTypeM4R; # define FourCC2Str(fourcc) (const char[]){*(((char*)&fourcc)+3), *(((char*)&fourcc)+2), *(((char*)&fourcc)+1), *(((char*)&fourcc)+0),0} #endif -static FourCharCode kMP42MediaType_Unknown = 'unkn'; +#define Str2FourCC(str) (str[0] << 24) + (str[1] << 16) + (str[2] << 8) + str[3] + + +enum : FourCharCode +{ + kMP42MediaType_Unknown = 'unkn' +}; // Media Type typedef FourCharCode MP42MediaType; @@ -41,6 +50,11 @@ enum : MP42MediaType kMP42MediaType_Subtitle = 'sbtl', kMP42MediaType_TimeCode = 'tmcd', kMP42MediaType_Metadata = 'meta', + kMP42MediaType_OD = 'odsm', + kMP42MediaType_Scene = 'sdsm', + kMP42MediaType_Subpic = 'subp', + kMP42MediaType_Hint = 'hint', + kMP42MediaType_Control = 'cnlt' }; // Video Format @@ -63,7 +77,7 @@ enum : MP42VideoCodecType kMP42VideoCodecType_SorensonVideo = 'SVQ1', kMP42VideoCodecType_SorensonVideo3 = 'SVQ3', - kMP42VideoCodecType_Theora = 'theo', + kMP42VideoCodecType_Theora = 'XiTh', kMP42VideoCodecType_VP8 = 'VP8 ', kMP42VideoCodecType_VP9 = 'VP9 ', @@ -135,6 +149,7 @@ enum : MP42AudioCodecType kMP42AudioCodecType_TrueHD = 'trhd', kMP42AudioCodecType_MLP = 'mlp ', kMP42AudioCodecType_Opus = 'Opus', + kMP42AudioCodecType_TTA = 'TTA1', kMP42AudioCodecType_FairPlay = 'drms' }; @@ -149,7 +164,7 @@ enum : MP42SubtitleCodecType kMP42SubtitleCodecType_VobSub = 'subp', kMP42SubtitleCodecType_PGS = 'PGS ', kMP42SubtitleCodecType_SSA = 'SSA ', - kMP42SubtitleCodecType_FairPlay = 'wvtt', + kMP42SubtitleCodecType_FairPlay = 'drmi', //FIXME }; // Closed Caption Fromat diff --git a/MP42/MP42MediaFormat.m b/MP42/MP42MediaFormat.m index 0c03ca4..5106426 100644 --- a/MP42/MP42MediaFormat.m +++ b/MP42/MP42MediaFormat.m @@ -6,7 +6,7 @@ // // -#import +#import "MP42MediaFormat.h" // File Type NSString *const MP42FileTypeMP4 = @"mp4"; @@ -15,73 +15,373 @@ NSString *const MP42FileTypeM4A = @"m4a"; NSString *const MP42FileTypeM4B = @"m4b"; NSString *const MP42FileTypeM4R = @"m4r"; - -// Media Type -NSString *const MP42MediaTypeVideo = @"Video Track"; -NSString *const MP42MediaTypeAudio = @"Sound Track"; -NSString *const MP42MediaTypeText = @"Text Track"; -NSString *const MP42MediaTypeClosedCaption = @"Closed Caption Track"; -NSString *const MP42MediaTypeSubtitle = @"Subtitle Track"; -NSString *const MP42MediaTypeTimecode = @"TimeCode Track"; - - -// Video Format -NSString *const MP42VideoFormatH265 = @"H.265"; -NSString *const MP42VideoFormatH264 = @"H.264"; -NSString *const MP42VideoFormatMPEG4Visual = @"MPEG-4 Visual"; -NSString *const MP42VideoFormatSorenson = @"Sorenson Video"; -NSString *const MP42VideoFormatSorenson3 = @"Sorenson Video 3"; -NSString *const MP42VideoFormatMPEG1 = @"MPEG-1"; -NSString *const MP42VideoFormatMPEG2 = @"MPEG-2"; -NSString *const MP42VideoFormatDV = @"DV"; -NSString *const MP42VideoFormatPNG = @"PNG"; -NSString *const MP42VideoFormatAnimation = @"Animation"; -NSString *const MP42VideoFormatProRes = @"Apple ProRes"; -NSString *const MP42VideoFormatJPEG = @"Photo-JPEG"; -NSString *const MP42VideoFormatMotionJPEG = @"Motion JPEG"; -NSString *const MP42VideoFormatFairPlay = @"FairPlay Video"; - - -// Audio Format -NSString *const MP42AudioFormatAAC = @"AAC"; -NSString *const MP42AudioFormatHEAAC = @"HE-AAC"; -NSString *const MP42AudioFormatMP1 = @"MP1"; -NSString *const MP42AudioFormatMP2 = @"MP2"; -NSString *const MP42AudioFormatMP3 = @"MP3"; -NSString *const MP42AudioFormatVorbis = @"Vorbis"; -NSString *const MP42AudioFormatFLAC = @"FLAC"; -NSString *const MP42AudioFormatALAC = @"ALAC"; -NSString *const MP42AudioFormatAC3 = @"AC-3"; -NSString *const MP42AudioFormatEAC3 = @"E-AC-3"; -NSString *const MP42AudioFormatDTS = @"DTS"; -NSString *const MP42AudioFormatTrueHD = @"True HD"; -NSString *const MP42AudioFormatOpus = @"Opus"; -NSString *const MP42AudioFormatAMR = @"AMR Narrow Band"; -NSString *const MP42AudioFormatPCM = @"PCM"; -NSString *const MP42AudioFormatFairPlay = @"FairPlay Sound"; - - -// Subtitle Format -NSString *const MP42SubtitleFormatWebVTT = @"WebVTT"; -NSString *const MP42SubtitleFormatTx3g = @"Tx3g"; -NSString *const MP42SubtitleFormatText = @"Text"; -NSString *const MP42SubtitleFormatVobSub = @"VobSub"; -NSString *const MP42SubtitleFormatPGS = @"PGS"; -NSString *const MP42SubtitleFormatSSA = @"SSA"; -NSString *const MP42SubtitleFormatFairPlay = @"FairPlay Tx3g"; - - -// Closed Caption Format -NSString *const MP42ClosedCaptionFormatFairPlay = @"FairPlay CEA-608"; -NSString *const MP42ClosedCaptionFormatCEA608 = @"CEA-608"; -NSString *const MP42ClosedCaptionFormatCEA708 = @"CEA-708"; - - -// TimeCode Format -NSString *const MP42TimeCodeFormat = @"TimeCode"; - // Audio Downmixes NSString * const SBMonoMixdown = @"SBMonoMixdown"; NSString * const SBStereoMixdown = @"SBStereoMixdown"; NSString * const SBDolbyMixdown = @"SBDolbyMixdown"; NSString * const SBDolbyPlIIMixdown = @"SBDolbyPlIIMixdown"; + +NSString *localizedMediaDisplayName(FourCharCode mediaType) +{ + NSString *result = @(FourCC2Str(mediaType)); + + switch (mediaType) { + case kMP42MediaType_Video: + result = NSLocalizedString(@"Video Track", nil); + break; + + case kMP42MediaType_Audio: + result = NSLocalizedString(@"Sound Track", nil); + break; + + case kMP42MediaType_Muxed: + result = NSLocalizedString(@"Muxed Track", nil); + break; + + case kMP42MediaType_Text: + result = NSLocalizedString(@"Text Track", nil); + break; + + case kMP42MediaType_ClosedCaption: + result = NSLocalizedString(@"Closed Caption Track", nil); + break; + + case kMP42MediaType_Subtitle: + case kMP42MediaType_Subpic: + result = NSLocalizedString(@"Subtitle Track", nil); + break; + + case kMP42MediaType_TimeCode: + result = NSLocalizedString(@"TimeCode Track", nil); + break; + + case kMP42MediaType_Metadata: + result = NSLocalizedString(@"Metadata Track", nil); + break; + + case kMP42MediaType_OD: + result = NSLocalizedString(@"MPEG-4 ODSM Track", nil); + break; + + case kMP42MediaType_Scene: + result = NSLocalizedString(@"MPEG-4 SDSM Track", nil); + break; + + case kMP42MediaType_Control: + result = NSLocalizedString(@"MPEG-4 Control Track", nil); + break; + + case kMP42MediaType_Hint: + result = NSLocalizedString(@"Hint Track", nil); + break; + + default: + break; + } + + return result; +} + +NSString *localizedVideoDisplayName(FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaSubtype) { + case kMP42VideoCodecType_Animation: + result = NSLocalizedString(@"Animation", nil); + break; + + case kMP42VideoCodecType_Cinepak: + result = NSLocalizedString(@"Cinepak", nil); + break; + + case kMP42VideoCodecType_JPEG: + result = NSLocalizedString(@"JPEG", nil); + break; + + case kMP42VideoCodecType_JPEG_OpenDML: + result = NSLocalizedString(@"JPEG OpenDML", nil); + break; + + case kMP42VideoCodecType_PNG: + result = NSLocalizedString(@"PNG", nil); + break; + + case kMP42VideoCodecType_H263: + result = NSLocalizedString(@"H.263", nil); + break; + + case kMP42VideoCodecType_H264: + result = NSLocalizedString(@"H.264", nil); + break; + + case kMP42VideoCodecType_HEVC: + case kMP42VideoCodecType_HEVC_2: + result = NSLocalizedString(@"HEVC", nil); + break; + + case kMP42VideoCodecType_MPEG4Video: + result = NSLocalizedString(@"MPEG-4 Visual", nil); + break; + + case kMP42VideoCodecType_MPEG2Video: + result = NSLocalizedString(@"MPEG-2 Video", nil); + break; + + case kMP42VideoCodecType_MPEG1Video: + result = NSLocalizedString(@"MPEG-1 Video", nil); + break; + + case kMP42VideoCodecType_SorensonVideo: + result = NSLocalizedString(@"Sorenson Video", nil); + break; + + case kMP42VideoCodecType_SorensonVideo3: + result = NSLocalizedString(@"Sorenson Video 3", nil); + break; + + case kMP42VideoCodecType_Theora: + result = NSLocalizedString(@"Theora", nil); + break; + + case kMP42VideoCodecType_VP8: + result = NSLocalizedString(@"VP8", nil); + break; + + case kMP42VideoCodecType_VP9: + result = NSLocalizedString(@"VP9", nil); + break; + + case kMP42VideoCodecType_AppleProRes4444: + result = NSLocalizedString(@"ProRes 4444", nil); + break; + + case kMP42VideoCodecType_AppleProRes422HQ: + result = NSLocalizedString(@"ProRes 422 HQ", nil); + break; + + case kMP42VideoCodecType_AppleProRes422: + result = NSLocalizedString(@"ProRes 422", nil); + break; + + case kMP42VideoCodecType_AppleProRes422LT: + result = NSLocalizedString(@"ProRes 422 LT", nil); + break; + + case kMP42VideoCodecType_AppleProRes422Proxy: + result = NSLocalizedString(@"ProRes 422 Proxy", nil); + break; + + case kMP42VideoCodecType_DVCNTSC: + result = NSLocalizedString(@"DV NTSC", nil); + break; + + case kMP42VideoCodecType_DVCPAL: + result = NSLocalizedString(@"DV PAL", nil); + break; + + case kMP42VideoCodecType_DVCProPAL: + result = NSLocalizedString(@"DVC Pro PAL", nil); + break; + + + default: + break; + } + + return result; +} + +NSString *localizedAudioDisplayName(FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaSubtype) { + case kMP42AudioCodecType_MPEG4AAC: + result = NSLocalizedString(@"AAC", nil); + break; + + case kMP42AudioCodecType_MPEG4AAC_HE: + result = NSLocalizedString(@"HE-AAC", nil); + break; + + case kMP42AudioCodecType_MPEGLayer1: + result = NSLocalizedString(@"MP1", nil); + break; + + case kMP42AudioCodecType_MPEGLayer2: + result = NSLocalizedString(@"MP2", nil); + break; + + case kMP42AudioCodecType_MPEGLayer3: + result = NSLocalizedString(@"Vorbis", nil); + break; + + case kMP42AudioCodecType_FLAC: + result = NSLocalizedString(@"FLAC", nil); + break; + + case kMP42AudioCodecType_AppleLossless: + result = NSLocalizedString(@"Apple Loseless", nil); + break; + + case kMP42AudioCodecType_AC3: + result = NSLocalizedString(@"AC-3", nil); + break; + + case kMP42AudioCodecType_EnhancedAC3: + result = NSLocalizedString(@"Enhanced AC-3", nil); + break; + + case kMP42AudioCodecType_DTS: + result = NSLocalizedString(@"DTS", nil); + break; + + case kMP42AudioCodecType_TrueHD: + result = NSLocalizedString(@"True HD", nil); + break; + + case kMP42AudioCodecType_Opus: + result = NSLocalizedString(@"Opus", nil); + break; + + case kMP42AudioCodecType_TTA: + result = NSLocalizedString(@"True Audio", nil); + break; + + case kMP42AudioCodecType_FairPlay: + result = NSLocalizedString(@"FairPlay Sound", nil); + break; + + case kMP42AudioCodecType_LinearPCM: + result = NSLocalizedString(@"PCM", nil); + break; + + default: + break; + } + + return result; +} + +NSString *localizedSubtitlesDisplayName(FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaSubtype) { + case kMP42SubtitleCodecType_Text: + result = NSLocalizedString(@"Text", nil); + break; + + case kMP42SubtitleCodecType_3GText: + result = NSLocalizedString(@"Tx3g", nil); + break; + + case kMP42SubtitleCodecType_WebVTT: + result = NSLocalizedString(@"WebVTT", nil); + break; + + case kMP42SubtitleCodecType_VobSub: + result = NSLocalizedString(@"VobSub", nil); + break; + + case kMP42SubtitleCodecType_PGS: + result = NSLocalizedString(@"PGS", nil); + break; + + case kMP42SubtitleCodecType_SSA: + result = NSLocalizedString(@"SSA", nil); + break; + + case kMP42SubtitleCodecType_FairPlay: + result = NSLocalizedString(@"FairPlay Tx3g", nil); + break; + + default: + break; + } + + return result; +} + +NSString *localizedClosedCaptionDisplayName(FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaSubtype) { + case kMP42ClosedCaptionCodecType_CEA608: + result = NSLocalizedString(@"CEA-608", nil); + break; + + case kMP42ClosedCaptionCodecType_CEA708: + result = NSLocalizedString(@"CEA-708", nil); + break; + + case kMP42ClosedCaptionCodecType_ATSC: + result = NSLocalizedString(@"ATSC", nil); + break; + + case kMP42ClosedCaptionCodecType_FairPlay: + result = NSLocalizedString(@"FairPlay CEA-608", nil); + break; + + default: + break; + } + + return result; +} + +NSString *localizedTimeCodeDisplayName(FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaSubtype) { + case kMP42TimeCodeFormatType_TimeCode32: + result = NSLocalizedString(@"TimeCode 32", nil); + break; + + case kMP42TimeCodeFormatType_TimeCode64: + result = NSLocalizedString(@"TimeCode 64", nil); + break; + + case kCMP42TimeCodeFormatType_Counter32: + result = NSLocalizedString(@"Counter 32", nil); + break; + + case kMP42TimeCodeFormatType_Counter64: + result = NSLocalizedString(@"Counter 64", nil); + break; + + default: + break; + } + + return result; +} + +NSString *localizedDisplayName(FourCharCode mediaType, FourCharCode mediaSubtype) +{ + NSString *result = @(FourCC2Str(mediaSubtype)); + + switch (mediaType) { + case kMP42MediaType_Video: + result = localizedVideoDisplayName(mediaSubtype); + break; + case kMP42MediaType_Audio: + result = localizedAudioDisplayName(mediaSubtype); + break; + case kMP42MediaType_Subtitle: + result = localizedSubtitlesDisplayName(mediaSubtype); + break; + case kMP42MediaType_ClosedCaption: + result = localizedClosedCaptionDisplayName(mediaSubtype); + break; + + + default: + break; + } + + return result; +} diff --git a/MP42/MP42MkvImporter.m b/MP42/MP42MkvImporter.m index 6ead11d..e207269 100644 --- a/MP42/MP42MkvImporter.m +++ b/MP42/MP42MkvImporter.m @@ -17,7 +17,6 @@ #import "MatroskaFile.h" #include "avutil.h" -#import "mp4v2.h" #import "MP42PrivateUtilities.h" #import "MP42FormatUtilites.h" #import "MP42Track+Muxer.h" @@ -70,7 +69,7 @@ } @end -int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t FilePos, uint8_t** frame, uint32_t *FrameSize) +static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t FilePos, uint8_t** frame, uint32_t *FrameSize) { uint8_t *packet = NULL; uint32_t iSize = *FrameSize; @@ -166,7 +165,6 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t return nil; } - //SegmentInfo *info = mkv_GetFileInfo(_matroskaFile); uint64_t *trackSizes = [self copyGuessedTrackDataLength]; NSInteger trackCount = mkv_GetNumTracks(_matroskaFile); @@ -226,7 +224,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t } if (newTrack) { - newTrack.format = [self matroskaCodecIDToHumanReadableName:mkvTrack]; + newTrack.format = CodecIDToFourCC(mkvTrack); newTrack.trackId = i; newTrack.sourceURL = self.fileURL; newTrack.dataLength = trackSizes[i]; @@ -255,10 +253,12 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t if (scaledDuration > _fileDuration) _fileDuration = scaledDuration; - if ([self matroskaTrackName:mkvTrack]) - newTrack.name = [self matroskaTrackName:mkvTrack]; + NSString *trackName = TrackNameToString(mkvTrack); + if (trackName) { + newTrack.name = trackName; + } iso639_lang_t *isoLanguage = lang_for_code2(mkvTrack->Language); - newTrack.language = [NSString stringWithUTF8String:isoLanguage->eng_name]; + newTrack.language = @(isoLanguage->eng_name); [self addTrack:newTrack]; [newTrack release]; @@ -397,80 +397,67 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t return trackSizes; } -- (FourCharCode)matroskaCodecIDToHumanReadableName:(TrackInfo *)track +// List of codec IDs we know about and that map to fourccs +static const struct { + const char *codecID; + FourCharCode fourCC; +} kCodecIDMap[] = { - if (track->CodecID) { - if (!strcmp(track->CodecID, "V_MPEG4/ISO/AVC")) - return kMP42VideoCodecType_H264; - else if (!strcmp(track->CodecID, "A_AAC") || - !strcmp(track->CodecID, "A_AAC/MPEG4/LC") || - !strcmp(track->CodecID, "A_AAC/MPEG2/LC")) - return kMP42AudioCodecType_MPEG4AAC; - else if (!strcmp(track->CodecID, "A_AC3")) - return kMP42AudioCodecType_AC3; - else if (!strcmp(track->CodecID, "A_EAC3")) - return kMP42AudioCodecType_EnhancedAC3; - else if (!strcmp(track->CodecID, "V_MPEG4/ISO/SP")) - return kMP42VideoCodecType_MPEG4Video; - else if (!strcmp(track->CodecID, "V_MPEG4/ISO/ASP")) - return kMP42VideoCodecType_MPEG4Video; - else if (!strcmp(track->CodecID, "V_MPEG2")) - return kMP42VideoCodecType_MPEG2Video; - else if (!strcmp(track->CodecID, "A_DTS")) - return kMP42AudioCodecType_DTS; - else if (!strcmp(track->CodecID, "A_OPUS")) - return kMP42AudioCodecType_Opus; - else if (!strcmp(track->CodecID, "A_VORBIS")) - return kMP42AudioCodecType_Vorbis; - else if (!strcmp(track->CodecID, "A_FLAC")) - return kMP42AudioCodecType_FLAC; - else if (!strcmp(track->CodecID, "A_MPEG/L1")) - return kMP42AudioCodecType_MPEGLayer1; - else if (!strcmp(track->CodecID, "A_MPEG/L2")) - return kMP42AudioCodecType_MPEGLayer2; - else if (!strcmp(track->CodecID, "A_MPEG/L3")) - return kMP42AudioCodecType_MPEGLayer3; - else if (!strcmp(track->CodecID, "A_TRUEHD")) - return kMP42AudioCodecType_TrueHD; - else if (!strcmp(track->CodecID, "A_MLP")) - return kMP42AudioCodecType_MLP; - else if (!strcmp(track->CodecID, "S_TEXT/UTF8")) - return kMP42SubtitleCodecType_Text; - else if (!strcmp(track->CodecID, "S_TEXT/ASS") - || !strcmp(track->CodecID, "S_TEXT/SSA")) - return kMP42SubtitleCodecType_SSA; - else if (!strcmp(track->CodecID, "S_VOBSUB")) - return kMP42SubtitleCodecType_VobSub; - else if (!strcmp(track->CodecID, "S_HDMV/PGS")) { - return kMP42SubtitleCodecType_PGS; - } - else if (!strcmp(track->CodecID, "V_MPEGH/ISO/HEVC")) { - return kMP42VideoCodecType_HEVC_2; - } - else if (!strcmp(track->CodecID, "V_THEORA")) { - return kMP42VideoCodecType_Theora; - } - else if (!strcmp(track->CodecID, "V_VP8")) { - return kMP42VideoCodecType_VP8; - } - else if (!strcmp(track->CodecID, "V_VP9")) { - return kMP42VideoCodecType_VP9; - } - else { - return kMP42MediaType_Unknown; + { "V_MPEG1", kMP42VideoCodecType_MPEG1Video }, + { "V_MPEG2", kMP42VideoCodecType_MPEG2Video }, + { "V_MPEG4/ISO/SP", kMP42VideoCodecType_MPEG4Video }, + { "V_MPEG4/ISO/ASP", kMP42VideoCodecType_MPEG4Video }, + { "V_MPEG4/ISO/AP", kMP42VideoCodecType_MPEG4Video }, + { "V_MPEG4/ISO/AVC", kMP42VideoCodecType_H264 }, + { "V_MPEGH/ISO/HEVC", kMP42VideoCodecType_HEVC_2 }, + { "V_THEORA", kMP42VideoCodecType_Theora }, + { "V_VP8", kMP42VideoCodecType_VP8 }, + { "V_VP9", kMP42VideoCodecType_VP9 }, + { "V_PRORES", kMP42VideoCodecType_AppleProRes422 }, + + { "A_AAC", kMP42AudioCodecType_MPEG4AAC }, + { "A_AAC/MPEG2/LC", kMP42AudioCodecType_MPEG4AAC }, + { "A_AAC/MPEG4/LC", kMP42AudioCodecType_MPEG4AAC }, + { "A_AAC/MPEG4/LC/SBR", kMP42AudioCodecType_MPEG4AAC_HE }, + { "A_AC3", kMP42AudioCodecType_AC3 }, + { "A_EAC3", kMP42AudioCodecType_EnhancedAC3 }, + { "A_DTS", kMP42AudioCodecType_DTS }, + { "A_OPUS", kMP42AudioCodecType_Opus }, + { "A_VORBIS", kMP42AudioCodecType_Vorbis }, + { "A_FLAC", kMP42AudioCodecType_FLAC }, + { "A_TRUEHD", kMP42AudioCodecType_TrueHD }, + { "A_MLP", kMP42AudioCodecType_MLP }, + { "A_MPEG/L1", kMP42AudioCodecType_MPEGLayer1 }, + { "A_MPEG/L2", kMP42AudioCodecType_MPEGLayer2 }, + { "A_MPEG/L3", kMP42AudioCodecType_MPEGLayer3 }, + { "A_TTA1", kMP42AudioCodecType_TTA }, + + { "S_TEXT/UTF8", kMP42SubtitleCodecType_Text }, + { "S_TEXT/WEBVTT", kMP42SubtitleCodecType_WebVTT }, + { "S_TEXT/ASS", kMP42SubtitleCodecType_SSA }, + { "S_TEXT/SSA", kMP42SubtitleCodecType_SSA }, + { "S_VOBSUB", kMP42SubtitleCodecType_VobSub }, + { "S_HDMV/PGS", kMP42SubtitleCodecType_PGS }, + + { NULL, kMP42MediaType_Unknown }, +}; + +static FourCharCode CodecIDToFourCC(TrackInfo *track) +{ + for (int i = 0; kCodecIDMap[i].fourCC != kMP42MediaType_Unknown; i++) { + if (!strcmp(track->CodecID, kCodecIDMap[i].codecID)) { + return kCodecIDMap[i].fourCC; } } - else { - return kMP42MediaType_Unknown; - } + return kMP42MediaType_Unknown; } -- (NSString *)matroskaTrackName:(TrackInfo *)track -{ - if(track->Name && strlen(track->Name)) - return [NSString stringWithUTF8String:track->Name]; - else - return nil; +static NSString * TrackNameToString(TrackInfo *track) +{ + if (track->Name && strlen(track->Name)) { + return @(track->Name); + } + return nil; } - (uint64_t)matroskaTrackStartTime:(TrackInfo *)track Id:(MP4TrackId)Id diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index 941f83a..acdd5eb 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -186,7 +186,8 @@ } // H.265 video track - else if ([track isMemberOfClass:[MP42VideoTrack class]] && track.format == kMP42VideoCodecType_HEVC) { + else if ([track isMemberOfClass:[MP42VideoTrack class]] && + (track.format == kMP42VideoCodecType_HEVC || track.format == kMP42VideoCodecType_HEVC_2)) { if (magicCookie.length < sizeof(uint8_t) * 6) { continue; diff --git a/MP42/MP42PrivateUtilities.h b/MP42/MP42PrivateUtilities.h index c40ef06..2a0f275 100644 --- a/MP42/MP42PrivateUtilities.h +++ b/MP42/MP42PrivateUtilities.h @@ -41,7 +41,7 @@ MP4TrackId findFirstVideoTrack(MP4FileHandle fileHandle); uint16_t getFixedVideoWidth(MP4FileHandle fileHandle, MP4TrackId videoTrack); NSString* getTrackName(MP4FileHandle fileHandle, MP4TrackId videoTrack); -FourCharCode getHumanReadableTrackMediaDataName(MP4FileHandle fileHandle, MP4TrackId Id); +FourCharCode getTrackMediaFormat(MP4FileHandle fileHandle, MP4TrackId Id); NSString* getHumanReadableTrackLanguage(MP4FileHandle fileHandle, MP4TrackId videoTrack); NSString* getFilenameLanguage(CFStringRef filename); diff --git a/MP42/MP42PrivateUtilities.m b/MP42/MP42PrivateUtilities.m index 5684dbc..1a2d135 100644 --- a/MP42/MP42PrivateUtilities.m +++ b/MP42/MP42PrivateUtilities.m @@ -178,35 +178,17 @@ NSString * getTrackName(MP4FileHandle fileHandle, MP4TrackId Id) char *trackName; if (MP4GetTrackName(fileHandle, Id, &trackName)) { - NSString * name = [NSString stringWithCString:trackName encoding: NSMacOSRomanStringEncoding]; + NSString *name = @(trackName); free(trackName); return name; } - const char* type = MP4GetTrackType(fileHandle, Id); - if (!strcmp(type, MP4_AUDIO_TRACK_TYPE)) - return NSLocalizedString(@"Sound Track", @"Sound Track"); - else if (!strcmp(type, MP4_VIDEO_TRACK_TYPE)) - return NSLocalizedString(@"Video Track", @"Video Track"); - else if (!strcmp(type, MP4_TEXT_TRACK_TYPE)) - return NSLocalizedString(@"Text Track", @"Text Track"); - else if (!strcmp(type, MP4_SUBTITLE_TRACK_TYPE)) - return NSLocalizedString(@"Subtitle Track", @"Subtitle Track"); - else if (!strcmp(type, "clcp")) - return NSLocalizedString(@"Closed Caption Track", @"Closed Caption Track"); - else if (!strcmp(type, MP4_OD_TRACK_TYPE)) - return NSLocalizedString(@"MPEG-4 ODSM Track", @"MPEG-4 ODSM Track"); - else if (!strcmp(type, MP4_SCENE_TRACK_TYPE)) - return NSLocalizedString(@"MPEG-4 SDSM Track", @"MPEG-4 SDSM Track"); - else if (!strcmp(type, "tmcd")) - return NSLocalizedString(@"Timecode Track", @"Timecode Track"); - else if (!strcmp(type, "subp")) - return NSLocalizedString(@"Subtitle Track", @"Subtitle Track"); - else - return NSLocalizedString(@"Unknown Track", @"Unknown Track"); + const char *type = MP4GetTrackType(fileHandle, Id); + FourCharCode code = Str2FourCC(type); + return localizedMediaDisplayName(code); } -FourCharCode getHumanReadableTrackMediaDataName(MP4FileHandle fileHandle, MP4TrackId Id) +FourCharCode getTrackMediaFormat(MP4FileHandle fileHandle, MP4TrackId Id) { const char* type = MP4GetTrackType(fileHandle, Id); const char* dataName = MP4GetTrackMediaDataName(fileHandle, Id); diff --git a/MP42/MP42SubtitleTrack.m b/MP42/MP42SubtitleTrack.m index 7f40d82..3b51e4d 100644 --- a/MP42/MP42SubtitleTrack.m +++ b/MP42/MP42SubtitleTrack.m @@ -70,7 +70,6 @@ - (instancetype)init { if ((self = [super init])) { - _name = [self defaultName]; _format = kMP42SubtitleCodecType_3GText; _mediaType = kMP42MediaType_Subtitle; } @@ -451,10 +450,6 @@ static void insertTagsFromStyleRecord(style_record record, NSMutableString *samp return self; } -- (NSString *)defaultName { - return @"Subtitles Track"; -} - - (void)dealloc { [super dealloc]; diff --git a/MP42/MP42Track.m b/MP42/MP42Track.m index 4fd56d7..3f4745f 100644 --- a/MP42/MP42Track.m +++ b/MP42/MP42Track.m @@ -35,7 +35,6 @@ _enabled = YES; _updatedProperty = [[NSMutableDictionary alloc] init]; _mediaCharacteristicTags = [[NSSet alloc] init]; - _name = @"Unknown Track"; } return self; } @@ -50,7 +49,7 @@ _updatedProperty = [[NSMutableDictionary alloc] init]; if (fileHandle) { - _format = getHumanReadableTrackMediaDataName(fileHandle, _trackId); + _format = getTrackMediaFormat(fileHandle, _trackId); _name = [getTrackName(fileHandle, _trackId) retain]; _language = [getHumanReadableTrackLanguage(fileHandle, _trackId) retain]; @@ -175,21 +174,10 @@ } if (_updatedProperty[@"name"] || !_muxed) { - if (![_name isEqualToString:@"Video Track"] && - ![_name isEqualToString:@"Sound Track"] && - ![_name isEqualToString:@"Subtitle Track"] && - ![_name isEqualToString:@"Text Track"] && - ![_name isEqualToString:@"Chapter Track"] && - ![_name isEqualToString:@"Closed Caption Track"] && - ![_name isEqualToString:@"Unknown Track"] && - _name != nil) { - - const char *cString = [_name cStringUsingEncoding:NSMacOSRomanStringEncoding]; - - if (cString) { - MP4SetTrackName(fileHandle, _trackId, cString); - } + NSString *defaultName = localizedMediaDisplayName(_mediaType); + if (![_name isEqualToString:defaultName] && _name != nil) { + MP4SetTrackName(fileHandle, _trackId, _name.UTF8String); } else { MP4SetTrackName(fileHandle, _trackId, "\0"); @@ -243,11 +231,14 @@ @synthesize extendedLanguageTag = _extendedLanguageTag; - (NSString *)name { + if (_name == nil) { + _name = localizedMediaDisplayName(_mediaType); + } return [[_name copy] autorelease]; } - (NSString *)defaultName { - return @"Unknown Track"; + return localizedMediaDisplayName(_mediaType); } - (void)setName:(NSString *)newName @@ -336,7 +327,7 @@ - (NSString *)formatSummary { - return @(FourCC2Str(_format)); + return localizedDisplayName(_mediaType, _format); } - (void)encodeWithCoder:(NSCoder *)coder @@ -444,7 +435,7 @@ } - (NSString *)description { - return [NSString stringWithFormat:@"Track: %d, %@, %@, %llu kbit/s, %@", [self trackId], [self name], [self timeString], [self dataLength] / [self duration] * 8, [self format]]; + return [NSString stringWithFormat:@"Track: %d, %@, %@, %llu kbit/s, %@", self.trackId, self.name, self.timeString, self.dataLength / self.duration * 8, localizedDisplayName(self.mediaType, self.format)]; } @synthesize timescale = _timescale; diff --git a/MP42/MP42Utilities.m b/MP42/MP42Utilities.m index 888088d..c72dd96 100644 --- a/MP42/MP42Utilities.m +++ b/MP42/MP42Utilities.m @@ -39,22 +39,23 @@ MP42Duration TimeFromString(NSString *time_string, MP42Duration timeScale) BOOL isTrackMuxable(FourCharCode format) { FourCharCode supportedFormats[] = {kMP42VideoCodecType_HEVC, - kMP42VideoCodecType_H264, - kMP42VideoCodecType_MPEG4Video, - kMP42VideoCodecType_JPEG, - kMP42AudioCodecType_MPEG4AAC, - kMP42AudioCodecType_MPEG4AAC_HE, - kMP42AudioCodecType_AppleLossless, - kMP42AudioCodecType_AC3, - kMP42AudioCodecType_EnhancedAC3, - kMP42AudioCodecType_DTS, - kMP42SubtitleCodecType_3GText, - kMP42SubtitleCodecType_Text, - kMP42ClosedCaptionCodecType_CEA608, - kMP42VideoCodecType_JPEG, - kMP42SubtitleCodecType_VobSub, - kMP42SubtitleCodecType_WebVTT, - 0}; + kMP42VideoCodecType_HEVC_2, + kMP42VideoCodecType_H264, + kMP42VideoCodecType_MPEG4Video, + kMP42VideoCodecType_JPEG, + kMP42VideoCodecType_PNG, + kMP42AudioCodecType_MPEG4AAC, + kMP42AudioCodecType_MPEG4AAC_HE, + kMP42AudioCodecType_AppleLossless, + kMP42AudioCodecType_AC3, + kMP42AudioCodecType_EnhancedAC3, + kMP42AudioCodecType_DTS, + kMP42ClosedCaptionCodecType_CEA608, + kMP42SubtitleCodecType_3GText, + kMP42SubtitleCodecType_Text, + kMP42SubtitleCodecType_VobSub, + kMP42SubtitleCodecType_WebVTT, + 0}; for (FourCharCode *currentFormat = supportedFormats; *currentFormat; currentFormat++) { if (*currentFormat == format) { @@ -73,6 +74,7 @@ BOOL trackNeedConversion(FourCharCode format) { kMP42AudioCodecType_MPEGLayer3, kMP42AudioCodecType_Opus, kMP42AudioCodecType_TrueHD, + kMP42AudioCodecType_MLP, kMP42SubtitleCodecType_SSA, kMP42SubtitleCodecType_Text, kMP42SubtitleCodecType_PGS, @@ -84,7 +86,8 @@ BOOL trackNeedConversion(FourCharCode format) { } } - return NO;} + return NO; +} int isHdVideo(uint64_t width, uint64_t height) { diff --git a/MP42/MP42VideoTrack.m b/MP42/MP42VideoTrack.m index a95da0a..7cbc2bb 100644 --- a/MP42/MP42VideoTrack.m +++ b/MP42/MP42VideoTrack.m @@ -95,7 +95,6 @@ - (instancetype)init { if ((self = [super init])) { - _name = [self defaultName]; _language = @"Unknown"; _mediaType = kMP42MediaType_Video; } @@ -176,10 +175,6 @@ return (_trackId > 0); } -- (NSString *)defaultName { - return @"Video Track"; -} - @synthesize width; @synthesize height;