3
我要修剪視頻的視頻:無法剪裁用AVAssetExportSession
-(void)trimVideo:(NSURL*)outputURL
{
//[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:outputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
NSString * outputFilePath = NSHomeDirectory();
outputFilePath = [outputFilePath stringByAppendingPathComponent:@"Library"];
outputFilePath = [outputFilePath stringByAppendingPathComponent:@"temp.mov"];
NSURL * outputFileUrl = [NSURL fileURLWithPath:outputFilePath];
exportSession.outputURL = outputFileUrl;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeMPEG4;
CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
//[exportSession release];
}];
}
但我得到的錯誤:
Export Complete 4 Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x2008f420 {NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save}
不完全知道如何解決。
收到錯誤: - [經理writeVideoToPhotoLibrary:[NSURL fileURLWithPath:outputURL]; – Warewolf
HELLO Khoool,你必須在你的課堂上創建這種方法。 (void)writeVideoToPhotoLibrary:(NSURL *)nsurlToSave { ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init]; NSURL * recordedVideoURL = nsurlToSave; if([library videoAtPathIsCompatibleWithSavedPhotosAlbum:recordedVideoURL]){ ];}} } [library release] } – TurboManolo
偉大的人。這工作完美。 – Kalaichelvan