我的应用程序做了一些处理,在某些时候它需要调用AVAssetExportSession.
如果会话已经开始,然后我对应用程序进行后台处理,一切都正常完成.不过,如果我的背景之前调用应用程序exportAsynchronouslyWithCompletionHandler.我收到此错误:
AVAssetExportSessionStatusFailed Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1e550db0 {NSLocalizedFailureReason=An unknown error occurred (-12985), NSUnderlyingError=0x1e574910 "The operation couldn’t be completed. (OSStatus error -12985.)", NSLocalizedDescription=The operation could not be completed}
是否可以在后台启动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];
}];
}
Run Code Online (Sandbox Code Playgroud)
但我得到错误: …
我正在开发一个录制视频的应用程序.录制结束后,我使用图书馆将GIF图像放在上面 .
我的代码用于播放视频和将gif图像作为叠加层
self.avPlayer = [AVPlayer playerWithURL:self.urlstring];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
videoLayer.frame = self.preview_view.bounds;
videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.preview_view.layer addSublayer:videoLayer];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"02" withExtension:@"gif"];
self.img_gif.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
Run Code Online (Sandbox Code Playgroud)
但现在我想合并并保存带有此GIF图像叠加的视频.我谷歌它没找到我想要的东西.
谢谢您的帮助