无法使用AVAssetExportSession修剪video
我想修剪video:
-(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}
不完全确定如何解决。
这个诀窍:
-(void)trimVideo:(NSURL*)videoToTrimURL { //[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoToTrimURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *outputURL = paths[0]; NSFileManager *manager = [NSFileManager defaultManager]; [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil]; outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"]; // Remove Existing File [manager removeItemAtPath:outputURL error:nil]; exportSession.outputURL = [NSURL fileURLWithPath:outputURL]; exportSession.shouldOptimizeForNetworkUse = YES; exportSession.outputFileType = AVFileTypeQuickTimeMovie; CMTime start = CMTimeMakeWithSeconds(1.0, 600); CMTime duration = CMTimeMakeWithSeconds(3.0, 600); CMTimeRange range = CMTimeRangeMake(start, duration); exportSession.timeRange = range; [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { switch (exportSession.status) { case AVAssetExportSessionStatusCompleted: [self writeVideoToPhotoLibrary:[NSURL fileURLWithPath:outputURL]]; NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error); break; case AVAssetExportSessionStatusFailed: NSLog(@"Failed:%@",exportSession.error); break; case AVAssetExportSessionStatusCancelled: NSLog(@"Canceled:%@",exportSession.error); break; default: break; } //[exportSession release]; }]; }
- 使用AVFoundation将章节信息添加到现有video
- AVFoundation导出方向错误
- 在后台工作的AVAssetExportSession
- 自定义AVVideoCompositing类不按预期方式工作
- ios 10中的AVAssetExportSession不适用于iPhone 7
- Swift 3:如何在video上添加水印? AVVideoCompositionCoreAnimationTool iOS 10问题
- iOS:在video中裁剪video奇怪的绿线左侧和底侧
- 模拟AVLayerVideoGravityResizeAspectFill:裁剪和中心video模仿预览,而不会失去清晰度
- iOS – AVAssestExportSession只能在播放AVPlayer后导出最多8首曲目