繁体   English   中英

导出视频资产时出现未知异常

[英]Unknown exception when exporting video asset

我有以下代码从照片中导出视频数据:

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 export ...]事件的行上引发了一个未识别的异常(禁用了断点)。 ExportSession有效,但在日志中显示outputFileType = (null) ,因此我必须手动设置它。

我可以看到视频的URL,例如file://private.mobile....MOV,它被相机捕获并存储在资产目录中(我可以用照片观看)。 它有2秒的长度。

拜托,帮帮我吧。 如何使用照片导出视频文件?

PS:使用PHImageManager导出图像效果非常好。

好的,我发现了这个问题。 文档中没有说明,但需要手动设置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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM