Cosmetics.
This commit is contained in:
1 parent
60cf96a6af
commit
ba273bc261
1 file changed
+40
-30
+40
-30
@@ -168,18 +168,19 @@
|
|||||||
|
|
||||||
_fileURL = [fileURL retain];
|
_fileURL = [fileURL retain];
|
||||||
_localAsset = [[AVAsset assetWithURL:_fileURL] retain];
|
_localAsset = [[AVAsset assetWithURL:_fileURL] retain];
|
||||||
|
|
||||||
_tracksArray = [[NSMutableArray alloc] init];
|
_tracksArray = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
NSArray *tracks = [_localAsset tracks];
|
NSArray *tracks = [_localAsset tracks];
|
||||||
|
|
||||||
NSArray *availableChapter = [_localAsset availableChapterLocales];
|
NSArray *availableChapter = [_localAsset availableChapterLocales];
|
||||||
MP42ChapterTrack *chapters = nil;
|
MP42ChapterTrack *chapters = nil;
|
||||||
|
|
||||||
|
// Checks if there is a chapter tracks
|
||||||
if ([tracks count]) {
|
if ([tracks count]) {
|
||||||
for (NSLocale *locale in availableChapter) {
|
for (NSLocale *locale in availableChapter) {
|
||||||
chapters = [[MP42ChapterTrack alloc] init];
|
chapters = [[MP42ChapterTrack alloc] init];
|
||||||
NSArray *chapterList = [_localAsset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:nil];
|
NSArray *chapterList = [_localAsset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:nil];
|
||||||
for (AVTimedMetadataGroup* chapterData in chapterList) {
|
for (AVTimedMetadataGroup *chapterData in chapterList) {
|
||||||
for (AVMetadataItem *item in [chapterData items]) {
|
for (AVMetadataItem *item in [chapterData items]) {
|
||||||
CMTime time = [item time];
|
CMTime time = [item time];
|
||||||
[chapters addChapter:[item stringValue] duration:time.value * time.timescale / 1000];
|
[chapters addChapter:[item stringValue] duration:time.value * time.timescale / 1000];
|
||||||
@@ -188,30 +189,31 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts the tracks to the MP42File types
|
||||||
for (AVAssetTrack *track in tracks) {
|
for (AVAssetTrack *track in tracks) {
|
||||||
MP42Track *newTrack = nil;
|
MP42Track *newTrack = nil;
|
||||||
|
|
||||||
|
// Retrieves the formatDescription
|
||||||
CMFormatDescriptionRef formatDescription = NULL;
|
CMFormatDescriptionRef formatDescription = NULL;
|
||||||
NSArray *formatDescriptions = track.formatDescriptions;
|
NSArray *formatDescriptions = track.formatDescriptions;
|
||||||
if ([formatDescriptions count] > 0)
|
if ([formatDescriptions count] > 0)
|
||||||
formatDescription = (CMFormatDescriptionRef)[formatDescriptions objectAtIndex:0];
|
formatDescription = (CMFormatDescriptionRef)[formatDescriptions objectAtIndex:0];
|
||||||
|
|
||||||
NSArray *trackMetadata = [track metadataForFormat:AVMetadataFormatQuickTimeUserData];
|
|
||||||
|
|
||||||
if ([[track mediaType] isEqualToString:AVMediaTypeVideo]) {
|
if ([[track mediaType] isEqualToString:AVMediaTypeVideo]) {
|
||||||
newTrack = [[MP42VideoTrack alloc] init];
|
// Video type, do the usual video things
|
||||||
|
MP42VideoTrack *videoTrack = [[MP42VideoTrack alloc] init];
|
||||||
CGSize naturalSize = [track naturalSize];
|
CGSize naturalSize = [track naturalSize];
|
||||||
|
|
||||||
[(MP42VideoTrack*)newTrack setTrackWidth: naturalSize.width];
|
videoTrack.trackWidth = naturalSize.width;
|
||||||
[(MP42VideoTrack*)newTrack setTrackHeight: naturalSize.height];
|
videoTrack.trackHeight = naturalSize.height;
|
||||||
|
|
||||||
[(MP42VideoTrack*)newTrack setWidth: naturalSize.width];
|
videoTrack.width = naturalSize.width;
|
||||||
[(MP42VideoTrack*)newTrack setHeight: naturalSize.height];
|
videoTrack.height = naturalSize.height;
|
||||||
|
|
||||||
if (formatDescription) {
|
if (formatDescription) {
|
||||||
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
|
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
|
||||||
[(MP42VideoTrack*)newTrack setWidth: dimensions.width];
|
videoTrack.width = dimensions.width;
|
||||||
[(MP42VideoTrack*)newTrack setHeight: dimensions.height];
|
videoTrack.height = dimensions.height;
|
||||||
|
|
||||||
// Reads the pixel aspect ratio information
|
// Reads the pixel aspect ratio information
|
||||||
CFDictionaryRef pixelAspectRatioFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_PixelAspectRatio);
|
CFDictionaryRef pixelAspectRatioFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_PixelAspectRatio);
|
||||||
@@ -219,8 +221,8 @@
|
|||||||
NSInteger hSpacing, vSpacing;
|
NSInteger hSpacing, vSpacing;
|
||||||
CFNumberGetValue(CFDictionaryGetValue(pixelAspectRatioFromCMFormatDescription, kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing), kCFNumberIntType, &hSpacing);
|
CFNumberGetValue(CFDictionaryGetValue(pixelAspectRatioFromCMFormatDescription, kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing), kCFNumberIntType, &hSpacing);
|
||||||
CFNumberGetValue(CFDictionaryGetValue(pixelAspectRatioFromCMFormatDescription, kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing), kCFNumberIntType, &vSpacing);
|
CFNumberGetValue(CFDictionaryGetValue(pixelAspectRatioFromCMFormatDescription, kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing), kCFNumberIntType, &vSpacing);
|
||||||
[(MP42VideoTrack*)newTrack setHSpacing:hSpacing];
|
videoTrack.hSpacing = hSpacing;
|
||||||
[(MP42VideoTrack*)newTrack setVSpacing:vSpacing];
|
videoTrack.vSpacing = vSpacing;
|
||||||
}
|
}
|
||||||
// Reads the clean aperture information
|
// Reads the clean aperture information
|
||||||
CFDictionaryRef cleanApertureFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_CleanAperture);
|
CFDictionaryRef cleanApertureFromCMFormatDescription = CMFormatDescriptionGetExtension(formatDescription, kCMFormatDescriptionExtension_CleanAperture);
|
||||||
@@ -236,48 +238,56 @@
|
|||||||
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureVerticalOffset),
|
CFNumberGetValue(CFDictionaryGetValue(cleanApertureFromCMFormatDescription, kCMFormatDescriptionKey_CleanApertureVerticalOffset),
|
||||||
kCFNumberDoubleType, &cleanApertureVerticalOffset);
|
kCFNumberDoubleType, &cleanApertureVerticalOffset);
|
||||||
|
|
||||||
[(MP42VideoTrack*)newTrack setCleanApertureWidthN:cleanApertureWidth];
|
videoTrack.cleanApertureWidthN = cleanApertureWidth;
|
||||||
[(MP42VideoTrack*)newTrack setCleanApertureWidthD:1];
|
videoTrack.cleanApertureWidthD = 1;
|
||||||
[(MP42VideoTrack*)newTrack setCleanApertureHeightN:cleanApertureHeight];
|
videoTrack.cleanApertureHeightN = cleanApertureHeight;
|
||||||
[(MP42VideoTrack*)newTrack setCleanApertureHeightD:1];
|
videoTrack.cleanApertureHeightD = 1;
|
||||||
[(MP42VideoTrack*)newTrack setHorizOffN:cleanApertureHorizontalOffset];
|
videoTrack.horizOffN = cleanApertureHorizontalOffset;
|
||||||
[(MP42VideoTrack*)newTrack setHorizOffD:1];
|
videoTrack.horizOffD = 1;
|
||||||
[(MP42VideoTrack*)newTrack setVertOffN:cleanApertureVerticalOffset];
|
videoTrack.vertOffN = cleanApertureVerticalOffset;
|
||||||
[(MP42VideoTrack*)newTrack setVertOffD:1];
|
videoTrack.VertOffD = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newTrack = videoTrack;
|
||||||
} else if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) {
|
} else if ([[track mediaType] isEqualToString:AVMediaTypeAudio]) {
|
||||||
newTrack = [[MP42AudioTrack alloc] init];
|
// Audio type, check the channel layout and channels number
|
||||||
|
MP42AudioTrack *audioTrack = [[MP42AudioTrack alloc] init];
|
||||||
|
|
||||||
if (formatDescription) {
|
if (formatDescription) {
|
||||||
size_t layoutSize = 0;
|
size_t layoutSize = 0;
|
||||||
const AudioChannelLayout *layout = CMAudioFormatDescriptionGetChannelLayout(formatDescription, &layoutSize);
|
const AudioChannelLayout *layout = CMAudioFormatDescriptionGetChannelLayout(formatDescription, &layoutSize);
|
||||||
|
|
||||||
if (layoutSize) {
|
if (layoutSize) {
|
||||||
[(MP42AudioTrack*)newTrack setChannels:AudioChannelLayoutTag_GetNumberOfChannels(layout->mChannelLayoutTag)];
|
audioTrack.channels = AudioChannelLayoutTag_GetNumberOfChannels(layout->mChannelLayoutTag);
|
||||||
[(MP42AudioTrack*)newTrack setChannelLayoutTag:layout->mChannelLayoutTag];
|
audioTrack.channelLayoutTag = layout->mChannelLayoutTag;
|
||||||
} else {
|
} else {
|
||||||
[(MP42AudioTrack*)newTrack setChannels:1];
|
audioTrack.channels = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newTrack = audioTrack;
|
||||||
} else if ([[track mediaType] isEqualToString:AVMediaTypeSubtitle]) {
|
} else if ([[track mediaType] isEqualToString:AVMediaTypeSubtitle]) {
|
||||||
|
// Subtitle type, nothing interesting here
|
||||||
newTrack = [[MP42SubtitleTrack alloc] init];
|
newTrack = [[MP42SubtitleTrack alloc] init];
|
||||||
} else if ([[track mediaType] isEqualToString:AVMediaTypeText]) {
|
} else if ([[track mediaType] isEqualToString:AVMediaTypeText]) {
|
||||||
// It looks like there is no way to know what text track is used for chapters in the original file.
|
// It looks like there is no way to know what text track is used for chapters in the original file.
|
||||||
if (chapters)
|
if (chapters) {
|
||||||
newTrack = chapters;
|
newTrack = chapters;
|
||||||
else
|
} else {
|
||||||
newTrack = [[MP42ChapterTrack alloc] init];
|
newTrack = [[MP42ChapterTrack alloc] init];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Unknown type
|
||||||
newTrack = [[MP42Track alloc] init];
|
newTrack = [[MP42Track alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the usual track properties
|
||||||
newTrack.format = [self formatForTrack:track];
|
newTrack.format = [self formatForTrack:track];
|
||||||
newTrack.Id = [track trackID];
|
newTrack.Id = [track trackID];
|
||||||
newTrack.sourceURL = _fileURL;
|
newTrack.sourceURL = _fileURL;
|
||||||
newTrack.dataLength = [track totalSampleDataLength];
|
newTrack.dataLength = [track totalSampleDataLength];
|
||||||
|
|
||||||
// "name" is undefined in AVMetadataFormat.h, so read the official track name "tnam", and then "name". On 10.7, "name" is returned as an NSData
|
// "name" is undefined in AVMetadataFormat.h, so read the official track name "tnam", and then "name". On 10.7, "name" is returned as an NSData
|
||||||
|
NSArray *trackMetadata = [track metadataForFormat:AVMetadataFormatQuickTimeUserData];
|
||||||
id trackName = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:AVMetadataQuickTimeUserDataKeyTrackName keySpace:nil] lastObject] value];
|
id trackName = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:AVMetadataQuickTimeUserDataKeyTrackName keySpace:nil] lastObject] value];
|
||||||
id trackName_oldFormat = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:@"name" keySpace:nil] lastObject] value];
|
id trackName_oldFormat = [[[AVMetadataItem metadataItemsFromArray:trackMetadata withKey:@"name" keySpace:nil] lastObject] value];
|
||||||
if (trackName && [trackName isKindOfClass:[NSString class]]) {
|
if (trackName && [trackName isKindOfClass:[NSString class]]) {
|
||||||
@@ -305,7 +315,7 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)convertMetadata {
|
- (void)convertMetadata {
|
||||||
NSArray *items = nil;
|
NSArray *items = nil;
|
||||||
NSDictionary *commonItemsDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Name", AVMetadataCommonKeyTitle,
|
NSDictionary *commonItemsDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Name", AVMetadataCommonKeyTitle,
|
||||||
//nil, AVMetadataCommonKeyCreator,
|
//nil, AVMetadataCommonKeyCreator,
|
||||||
@@ -559,14 +569,14 @@
|
|||||||
else if (code == kCMVideoCodecType_MPEG4Video)
|
else if (code == kCMVideoCodecType_MPEG4Video)
|
||||||
magicCookie = CFDictionaryGetValue(atoms, @"esds");
|
magicCookie = CFDictionaryGetValue(atoms, @"esds");
|
||||||
|
|
||||||
return (NSData*)magicCookie;
|
return (NSData *)magicCookie;
|
||||||
} else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeAudio]) {
|
} else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeAudio]) {
|
||||||
size_t cookieSizeOut;
|
size_t cookieSizeOut;
|
||||||
const void *magicCookie = CMAudioFormatDescriptionGetMagicCookie(formatDescription, &cookieSizeOut);
|
const void *magicCookie = CMAudioFormatDescriptionGetMagicCookie(formatDescription, &cookieSizeOut);
|
||||||
|
|
||||||
if (code == kAudioFormatMPEG4AAC || code == kAudioFormatMPEG4AAC_HE || code == kAudioFormatMPEG4AAC_HE_V2) {
|
if (code == kAudioFormatMPEG4AAC || code == kAudioFormatMPEG4AAC_HE || code == kAudioFormatMPEG4AAC_HE_V2) {
|
||||||
// Extract DecoderSpecific info
|
// Extract DecoderSpecific info
|
||||||
UInt8* buffer;
|
UInt8 *buffer;
|
||||||
int size;
|
int size;
|
||||||
ReadESDSDescExt((void*)magicCookie, &buffer, &size, 0);
|
ReadESDSDescExt((void*)magicCookie, &buffer, &size, 0);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user