Files
MP42Foundation/MP42/MP42Utilities.m
T
Brian Gerfort 5e821d87f6 * Support for DTS to AC3 + AAC conversion.
If you prefer to recompile FFmpeg from scratch, make sure you include the --enable-encoder=ac3 and --disable-iconv parameters. My config:

./configure --disable-programs --disable-filters --disable-everything --disable-avdevice --disable-swscale --enable-avresample --enable-decoder=dvdsub --enable-decoder=pgssub --enable-decoder=aac --enable-decoder=mp3 --enable-decoder=mp2 --enable-decoder=mp1 --enable-decoder=ac3 --enable-decoder=eac3 --enable-decoder=truehd --enable-decoder=alac --enable-decoder=opus --enable-decoder=vorbis --enable-decoder=flac --enable-decoder=mlp --enable-decoder=dca --enable-decoder=pcm --enable-filter=aresample --enable-parser=opus --enable-muxer=opus --prefix=/Users/damians/Desktop/iffmpeg --extra-cxxflags='-mmacosx-version-min=10.9' --extra-cflags='-mmacosx-version-min=10.9' --extra-ldflags='-mmacosx-version-min=10.9' --enable-decoder=pcm_f32be --enable-decoder=pcm_f32le --enable-decoder=pcm_f64be --enable-decoder=pcm_f64le --enable-decoder=pcm_s16be --enable-decoder=pcm_s16le --enable-decoder=pcm_s16le_planar --enable-decoder=pcm_s24be --enable-decoder=pcm_daud --enable-decoder=pcm_s24le --enable-decoder=pcm_s32be --enable-decoder=pcm_s32le --enable-decoder=pcm_s8 --enable-decoder=pcm_u8 --enable-decoder=pcm_u16be --enable-decoder=pcm_u16le --enable-decoder=pcm_u24be --enable-decoder=pcm_u24le --enable-encoder=ac3 --disable-iconv
2017-05-05 15:41:25 +02:00

137 lines
4.9 KiB
Objective-C

//
// MP42Utilities.m
// MP42Foundation
//
// Created by Damiano Galassi on 16/11/13.
// Copyright (c) 2013 Damiano Galassi. All rights reserved.
//
#import "MP42Utilities.h"
#import "MP42SubUtilities.h"
#import <AudioToolbox/AudioToolbox.h>
NSString * StringFromTime(long long time, long timeScale)
{
NSString *time_string;
int hour, minute, second, frame;
long long result;
result = time / timeScale; // second
frame = time % timeScale;
second = result % 60;
result = result / 60; // minute
minute = result % 60;
result = result / 60; // hour
hour = result;
time_string = [NSString stringWithFormat:@"%d:%02d:%02d.%03d", hour, minute, second, frame]; // h:mm:ss.mss
return time_string;
}
MP42Duration TimeFromString(NSString *time_string, MP42Duration timeScale)
{
return ParseSubTime(time_string.UTF8String, timeScale, NO);
}
BOOL isTrackMuxable(FourCharCode format)
{
FourCharCode supportedFormats[] = {kMP42VideoCodecType_HEVC,
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) {
return YES;
}
}
return NO;
}
BOOL trackNeedConversion(FourCharCode format) {
FourCharCode supportedConversionFormats[] = {kMP42AudioCodecType_Vorbis,
kMP42AudioCodecType_FLAC,
kMP42AudioCodecType_MPEGLayer1,
kMP42AudioCodecType_MPEGLayer2,
kMP42AudioCodecType_MPEGLayer3,
kMP42AudioCodecType_Opus,
kMP42AudioCodecType_TrueHD,
kMP42AudioCodecType_MLP,
kMP42SubtitleCodecType_SSA,
kMP42SubtitleCodecType_Text,
kMP42SubtitleCodecType_PGS,
kMP42AudioCodecType_LinearPCM,
0};
for (FourCharCode *currentFormat = supportedConversionFormats; *currentFormat; currentFormat++) {
if (*currentFormat == format) {
return YES;
}
}
return NO;
}
int isHdVideo(uint64_t width, uint64_t height)
{
if ((width > 1280) || (height > 720))
return 2;
else if (((width >= 960) && (height >= 720)) || width >= 1280)
return 1;
return 0;
}
NSString *nameForChannelLayoutTag(UInt32 channelLayoutTag)
{
UInt32 channelLayoutSize = sizeof(AudioChannelLayout);
AudioChannelLayout *channelLayout = calloc(channelLayoutSize, 1);
channelLayout->mChannelLayoutTag = channelLayoutTag;
UInt32 bitmapSize = sizeof(UInt32);
UInt32 channelBitmap;
OSStatus err = AudioFormatGetProperty(kAudioFormatProperty_BitmapForLayoutTag,
sizeof(AudioChannelLayoutTag), &channelLayout->mChannelLayoutTag,
&bitmapSize, &channelBitmap);
UInt32 channels = AudioChannelLayoutTag_GetNumberOfChannels(channelLayout->mChannelLayoutTag);
if (err && channels == 6) {
channelBitmap = 0x3F;
}
free(channelLayout);
BOOL lfe = (channelBitmap & kAudioChannelBit_LFEScreen);
int mainChannels = (lfe) ? channels - 1 : channels;
NSString *desc;
switch (mainChannels) {
case 1:
desc = @"Mono";
break;
case 2:
case 3:
desc = @"Stereo";
break;
default:
desc = @"Surround";
break;
}
return [NSString stringWithFormat:@"%@ %d.%d", desc, mainChannels, (lfe) ? 1 : 0];
}