Add an additional check in TheTVDB.m initialize.
This commit is contained in:
1 parent
5b334e60cb
commit
b2dfc243a2
5 files changed
+440
-320
No files matched your search
+17
-4
@@ -24,7 +24,13 @@ extern NSString * const MP42GenerateChaptersPreviewTrack;
|
|||||||
extern NSString * const MP42CustomChaptersPreviewTrack;
|
extern NSString * const MP42CustomChaptersPreviewTrack;
|
||||||
extern NSString * const MP42OrganizeAlternateGroups;
|
extern NSString * const MP42OrganizeAlternateGroups;
|
||||||
|
|
||||||
@protocol MP42FileDelegate
|
typedef enum MP42Status : NSInteger {
|
||||||
|
MP42StatusLoaded = 0,
|
||||||
|
MP42StatusReading,
|
||||||
|
MP42StatusWriting
|
||||||
|
} MP42Status;
|
||||||
|
|
||||||
|
@protocol MP42FileDelegate <NSObject>
|
||||||
@optional
|
@optional
|
||||||
- (void)progressStatus:(CGFloat)progress;
|
- (void)progressStatus:(CGFloat)progress;
|
||||||
- (void)endSave:(id)sender;
|
- (void)endSave:(id)sender;
|
||||||
@@ -41,6 +47,8 @@ extern NSString * const MP42OrganizeAlternateGroups;
|
|||||||
NSMutableDictionary *_importers;
|
NSMutableDictionary *_importers;
|
||||||
|
|
||||||
BOOL _hasFileRepresentation;
|
BOOL _hasFileRepresentation;
|
||||||
|
|
||||||
|
MP42Status _status;
|
||||||
BOOL _cancelled;
|
BOOL _cancelled;
|
||||||
|
|
||||||
NSMutableArray *_tracks;
|
NSMutableArray *_tracks;
|
||||||
@@ -52,7 +60,7 @@ extern NSString * const MP42OrganizeAlternateGroups;
|
|||||||
|
|
||||||
@property(readonly) NSURL *URL;
|
@property(readonly) NSURL *URL;
|
||||||
@property(readonly) MP42Metadata *metadata;
|
@property(readonly) MP42Metadata *metadata;
|
||||||
@property(readonly, copy) NSArray *tracks;
|
@property(readonly) NSArray *tracks;
|
||||||
|
|
||||||
@property(readonly) BOOL hasFileRepresentation;
|
@property(readonly) BOOL hasFileRepresentation;
|
||||||
@property(readonly) NSUInteger duration;
|
@property(readonly) NSUInteger duration;
|
||||||
@@ -73,12 +81,17 @@ extern NSString * const MP42OrganizeAlternateGroups;
|
|||||||
- (void)moveTrackAtIndex:(NSUInteger)index toIndex:(NSUInteger)newIndex;
|
- (void)moveTrackAtIndex:(NSUInteger)index toIndex:(NSUInteger)newIndex;
|
||||||
|
|
||||||
- (MP42ChapterTrack *)chapters;
|
- (MP42ChapterTrack *)chapters;
|
||||||
|
/**
|
||||||
|
* Create a set of alternate group the way iTunes and Apple devices want:
|
||||||
|
* one alternate group for sound, one for subtitles, a disabled photo-jpeg track,
|
||||||
|
* a disabled chapter track, and a video track with no alternate group
|
||||||
|
*/
|
||||||
- (void)organizeAlternateGroups;
|
- (void)organizeAlternateGroups;
|
||||||
|
|
||||||
|
- (BOOL)optimize;
|
||||||
|
|
||||||
- (BOOL)writeToUrl:(NSURL *)url withAttributes:(NSDictionary *)attributes error:(NSError **)outError;
|
- (BOOL)writeToUrl:(NSURL *)url withAttributes:(NSDictionary *)attributes error:(NSError **)outError;
|
||||||
- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError;
|
- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError;
|
||||||
- (BOOL)optimize;
|
|
||||||
|
|
||||||
- (void)cancel;
|
- (void)cancel;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
+275
-316
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// MP42PreviewGenerator.h
|
||||||
|
// MP42Foundation
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 08/01/14.
|
||||||
|
// Copyright (c) 2014 Damiano Galassi. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@interface MP42PreviewGenerator : NSObject
|
||||||
|
|
||||||
|
|
||||||
|
+ (NSArray *)generatePreviewImagesFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
|
||||||
|
|
||||||
|
+ (NSArray *)generatePreviewImagesQTKitFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
|
||||||
|
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray *)chapters andFile:(NSURL *)file;
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
//
|
||||||
|
// MP42PreviewGenerator.m
|
||||||
|
// MP42Foundation
|
||||||
|
//
|
||||||
|
// Created by Damiano Galassi on 08/01/14.
|
||||||
|
// Copyright (c) 2014 Damiano Galassi. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MP42PreviewGenerator.h"
|
||||||
|
#import "MP42TextSample.h"
|
||||||
|
#import <QTKit/QTKit.h>
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
|
||||||
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@implementation MP42PreviewGenerator
|
||||||
|
|
||||||
|
+ (NSArray *)generatePreviewImagesFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
|
||||||
|
NSArray *images = nil;
|
||||||
|
// If we are on 10.7 or later, use AVFoundation, else QTKit
|
||||||
|
if (NSClassFromString(@"AVAsset")) {
|
||||||
|
images = [MP42PreviewGenerator generatePreviewImagesAVFoundationFromChapters:chapters andFile:file];
|
||||||
|
} else {
|
||||||
|
images = [MP42PreviewGenerator generatePreviewImagesQTKitFromChapters:chapters andFile:file];
|
||||||
|
}
|
||||||
|
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *)generatePreviewImagesQTKitFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
|
||||||
|
__block QTMovie * qtMovie;
|
||||||
|
|
||||||
|
// QTMovie objects must always be create on the main thread.
|
||||||
|
NSDictionary *movieAttributes = @{QTMovieURLAttribute: file,
|
||||||
|
QTMovieAskUnresolvedDataRefsAttribute: @NO,
|
||||||
|
@"QTMovieOpenForPlaybackAttribute": @YES,
|
||||||
|
@"QTMovieOpenAsyncRequiredAttribute": @NO,
|
||||||
|
@"QTMovieOpenAsyncOKAttribute": @NO,
|
||||||
|
QTMovieApertureModeAttribute: QTMovieApertureModeClean};
|
||||||
|
|
||||||
|
if (dispatch_get_current_queue() != dispatch_get_main_queue()) {
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qtMovie = [[QTMovie alloc] initWithAttributes:movieAttributes error:nil];
|
||||||
|
|
||||||
|
if (!qtMovie)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
for (QTTrack *qtTrack in [qtMovie tracksOfMediaType:@"sbtl"])
|
||||||
|
[qtTrack setAttribute:@NO forKey:QTTrackEnabledAttribute];
|
||||||
|
|
||||||
|
NSDictionary *attributes = [NSDictionary dictionaryWithObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType];
|
||||||
|
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
|
||||||
|
|
||||||
|
for (MP42TextSample *chapter in chapters) {
|
||||||
|
QTTime chapterTime = {
|
||||||
|
[chapter timestamp] + 1500, // Add a short offset, hopefully we will get a better image
|
||||||
|
1000, // if there is a fade
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
NSImage *frame = [qtMovie frameImageAtTime:chapterTime withAttributes:attributes error:nil];
|
||||||
|
|
||||||
|
if (images)
|
||||||
|
[images addObject:frame];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the movie, we don't want to keep it open while we are writing in it using another library.
|
||||||
|
// I am not sure if it is safe to release a QTMovie from a background thread, let's do it on the main just to be sure.
|
||||||
|
if (dispatch_get_current_queue() != dispatch_get_main_queue()) {
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||||
|
[qtMovie release];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[qtMovie release];
|
||||||
|
|
||||||
|
return [images autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
|
||||||
|
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
|
||||||
|
|
||||||
|
// If we are on 10.7, use the AVFoundation path
|
||||||
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
|
||||||
|
AVAsset *asset = [AVAsset assetWithURL:file];
|
||||||
|
|
||||||
|
if ([asset tracksWithMediaCharacteristic:AVMediaCharacteristicVisual]) {
|
||||||
|
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
|
||||||
|
generator.appliesPreferredTrackTransform = YES;
|
||||||
|
generator.apertureMode = AVAssetImageGeneratorApertureModeCleanAperture;
|
||||||
|
generator.requestedTimeToleranceBefore = kCMTimeZero;
|
||||||
|
generator.requestedTimeToleranceAfter = kCMTimeZero;
|
||||||
|
|
||||||
|
for (MP42TextSample * chapter in chapters) {
|
||||||
|
CMTime time = CMTimeMake([chapter timestamp] + 1800, 1000);
|
||||||
|
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
|
||||||
|
if (imgRef) {
|
||||||
|
NSSize size = NSMakeSize(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
|
||||||
|
NSImage *frame = [[NSImage alloc] initWithCGImage:imgRef size:size];
|
||||||
|
|
||||||
|
[images addObject:frame];
|
||||||
|
[frame release];
|
||||||
|
}
|
||||||
|
|
||||||
|
CGImageRelease(imgRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return [images autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -68,6 +68,10 @@
|
|||||||
A910B631183951010064028F /* QuickTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A925AABD1837A1A100BE84D4 /* QuickTime.framework */; };
|
A910B631183951010064028F /* QuickTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A925AABD1837A1A100BE84D4 /* QuickTime.framework */; };
|
||||||
A910B6321839510B0064028F /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9B9C4921823986200416A4E /* Quartz.framework */; };
|
A910B6321839510B0064028F /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9B9C4921823986200416A4E /* Quartz.framework */; };
|
||||||
A910B6331839511A0064028F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9B9C2D91823971F00416A4E /* AudioToolbox.framework */; };
|
A910B6331839511A0064028F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9B9C2D91823971F00416A4E /* AudioToolbox.framework */; };
|
||||||
|
A91711E6187D547D00459495 /* MP42PreviewGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = A91711E4187D547D00459495 /* MP42PreviewGenerator.h */; };
|
||||||
|
A91711E7187D547D00459495 /* MP42PreviewGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = A91711E4187D547D00459495 /* MP42PreviewGenerator.h */; };
|
||||||
|
A91711E8187D547D00459495 /* MP42PreviewGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = A91711E5187D547D00459495 /* MP42PreviewGenerator.m */; };
|
||||||
|
A91711E9187D547D00459495 /* MP42PreviewGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = A91711E5187D547D00459495 /* MP42PreviewGenerator.m */; };
|
||||||
A925AAAF18379AF800BE84D4 /* MP42Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AAAD18379AF800BE84D4 /* MP42Utilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
A925AAAF18379AF800BE84D4 /* MP42Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AAAD18379AF800BE84D4 /* MP42Utilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
A925AAB018379AF800BE84D4 /* MP42Utilities.m in Sources */ = {isa = PBXBuildFile; fileRef = A925AAAE18379AF800BE84D4 /* MP42Utilities.m */; };
|
A925AAB018379AF800BE84D4 /* MP42Utilities.m in Sources */ = {isa = PBXBuildFile; fileRef = A925AAAE18379AF800BE84D4 /* MP42Utilities.m */; };
|
||||||
A925AABC1837A16500BE84D4 /* QTKitDecrap.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AABB1837A16500BE84D4 /* QTKitDecrap.h */; };
|
A925AABC1837A16500BE84D4 /* QTKitDecrap.h in Headers */ = {isa = PBXBuildFile; fileRef = A925AABB1837A16500BE84D4 /* QTKitDecrap.h */; };
|
||||||
@@ -247,6 +251,8 @@
|
|||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
A910B5A318394E900064028F /* libmp42.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmp42.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
A910B5A318394E900064028F /* libmp42.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmp42.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
A91711E4187D547D00459495 /* MP42PreviewGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42PreviewGenerator.h; sourceTree = "<group>"; };
|
||||||
|
A91711E5187D547D00459495 /* MP42PreviewGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42PreviewGenerator.m; sourceTree = "<group>"; };
|
||||||
A925AAAD18379AF800BE84D4 /* MP42Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Utilities.h; sourceTree = "<group>"; };
|
A925AAAD18379AF800BE84D4 /* MP42Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP42Utilities.h; sourceTree = "<group>"; };
|
||||||
A925AAAE18379AF800BE84D4 /* MP42Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42Utilities.m; sourceTree = "<group>"; };
|
A925AAAE18379AF800BE84D4 /* MP42Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MP42Utilities.m; sourceTree = "<group>"; };
|
||||||
A925AABB1837A16500BE84D4 /* QTKitDecrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QTKitDecrap.h; sourceTree = "<group>"; };
|
A925AABB1837A16500BE84D4 /* QTKitDecrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QTKitDecrap.h; sourceTree = "<group>"; };
|
||||||
@@ -631,6 +637,8 @@
|
|||||||
A9B9C4A418239B7E00416A4E /* Utility */ = {
|
A9B9C4A418239B7E00416A4E /* Utility */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
A91711E4187D547D00459495 /* MP42PreviewGenerator.h */,
|
||||||
|
A91711E5187D547D00459495 /* MP42PreviewGenerator.m */,
|
||||||
A989F10D1823B3B40070AD8C /* MP42TextSample.h */,
|
A989F10D1823B3B40070AD8C /* MP42TextSample.h */,
|
||||||
A989F10E1823B3B40070AD8C /* MP42TextSample.m */,
|
A989F10E1823B3B40070AD8C /* MP42TextSample.m */,
|
||||||
A9B9C2381823923100416A4E /* MP42Image.h */,
|
A9B9C2381823923100416A4E /* MP42Image.h */,
|
||||||
@@ -682,6 +690,7 @@
|
|||||||
isa = PBXHeadersBuildPhase;
|
isa = PBXHeadersBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
A91711E7187D547D00459495 /* MP42PreviewGenerator.h in Headers */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -722,6 +731,7 @@
|
|||||||
A9B9C2D6182396FB00416A4E /* baseapi.h in Headers */,
|
A9B9C2D6182396FB00416A4E /* baseapi.h in Headers */,
|
||||||
A9B9C2991823923200416A4E /* MP42SubUtilities.h in Headers */,
|
A9B9C2991823923200416A4E /* MP42SubUtilities.h in Headers */,
|
||||||
A9B9C28B1823923200416A4E /* MP42Mp4Importer.h in Headers */,
|
A9B9C28B1823923200416A4E /* MP42Mp4Importer.h in Headers */,
|
||||||
|
A91711E6187D547D00459495 /* MP42PreviewGenerator.h in Headers */,
|
||||||
A9B9C2951823923200416A4E /* MP42SrtImporter.h in Headers */,
|
A9B9C2951823923200416A4E /* MP42SrtImporter.h in Headers */,
|
||||||
A9B9C2701823923200416A4E /* MP42BitmapSubConverter.h in Headers */,
|
A9B9C2701823923200416A4E /* MP42BitmapSubConverter.h in Headers */,
|
||||||
A9B9C2721823923200416A4E /* MP42CCImporter.h in Headers */,
|
A9B9C2721823923200416A4E /* MP42CCImporter.h in Headers */,
|
||||||
@@ -889,6 +899,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
A91711E9187D547D00459495 /* MP42PreviewGenerator.m in Sources */,
|
||||||
A910B5C618394EB20064028F /* MP42File.m in Sources */,
|
A910B5C618394EB20064028F /* MP42File.m in Sources */,
|
||||||
A910B5C818394EB20064028F /* MP42Track.m in Sources */,
|
A910B5C818394EB20064028F /* MP42Track.m in Sources */,
|
||||||
A910B5CA18394EB20064028F /* MP42VideoTrack.m in Sources */,
|
A910B5CA18394EB20064028F /* MP42VideoTrack.m in Sources */,
|
||||||
@@ -938,6 +949,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
A91711E8187D547D00459495 /* MP42PreviewGenerator.m in Sources */,
|
||||||
A9B9C2A01823923200416A4E /* MP42VideoTrack.m in Sources */,
|
A9B9C2A01823923200416A4E /* MP42VideoTrack.m in Sources */,
|
||||||
A9B9C27E1823923200416A4E /* MP42FileImporter.m in Sources */,
|
A9B9C27E1823923200416A4E /* MP42FileImporter.m in Sources */,
|
||||||
A9B9C27A1823923200416A4E /* MP42Fifo.m in Sources */,
|
A9B9C27A1823923200416A4E /* MP42Fifo.m in Sources */,
|
||||||
|
|||||||
Reference in new issue
Block a user