【问题标题】:Unknown exception when exporting video asset导出视频资产时出现未知异常
【发布时间】:2015-09-21 09:37:52
【问题描述】:

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

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 秒。

请帮帮我。如何使用照片导出视频文件?

P.S.:使用 PHImageManager 导出图像效果很好。

【问题讨论】:

  • 你说“未识别的异常”……你到底看到了什么?
  • 我只看到一个异常(应用程序中断)告诉类似 EXC_BREAKPOINT 指向 [exportSession exportAsynchronously...] 的行。
  • 如果它说断点,而你确实没有设置断点,这听起来像是 Xcode 糊涂了。
  • 请检查我编辑的问题
  • 你试过 [PHImageManager requestExportSessionForVideo:options:exportPreset:resultHandler:] 吗? (developer.apple.com/library/prerelease/ios/documentation/Photos/…)

标签: ios photosframework


【解决方案1】:

好的,我找到了问题所在。 文档中没有说,但是需要手动设置 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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 2013-01-03
    相关资源
    最近更新 更多