我有以下代码从照片中导出视频数据:
if (asset.mediaType == PHAssetMediaTypeVideo)
{
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
[[SharedManager sharedInstance] insertAttachment:exportSession.outputURL forEvent:event];
}];
}];
}此代码在exportSession导出的行中引发一个未确定的异常(禁用断点).一件事。ExportSession是有效的,但是在日志中显示outputFileType = (null),所以我不得不手动设置它。
我可以看到视频的网址,类似于file://private.mobile....MOV,--它是由照相机拍摄的,存储在资产目录中(我可以用照片观看)。它有2秒长。
求你帮帮我。如何使用照片导出视频文件?
P.S.:使用PHImageManager导出图像非常好。
发布于 2015-09-23 11:53:36
好吧,我发现问题了。文档中没有这样说,但是需要手动设置outputURL。因此,以下代码(来自这个答案https://stackoverflow.com/a/20244790/773451)是必需的:
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.mov"];
// Remove Existing File
[manager removeItemAtPath:outputURL error:nil];
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];https://stackoverflow.com/questions/32691874
复制相似问题