我正在尝试从UIImagePickerController创建的源视频中导出.mov文件。问题在于AVAssetExportSession创建的输出文件只有668个字节。为什么会失败?我的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *imagePickerVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *filename = @"vid1.mov";
AVAsset *video = [AVAsset assetWithURL:imagePickerVideoURL];
AVAssetExportSession *exportSession
= [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.outputURL = [pathToSavedVideosDirectory URLByAppendingPathComponent:filename];
NSLog(@"processing video...: %@", exportSession);
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"done processing video!");
}];
}
最佳答案
我猜这是因为exportSession
没有保留在内存中,因此在didFinishPickingMediaWithInfo
完成之后(在导出会话完成处理程序运行之前)被杀死了。
将exportSession
存储为@property
或更改您的完成处理程序以复制对exportSession
的引用,如下所示:
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if (AVAssetExportSessionStatusCompleted == exportSession.status)
{
NSLog(@"done processing video!");
}
}];