【问题标题】:Bad Access error on AVAssetExportSession on exportAsynchronouslyWithCompletionHandler call在 exportAsynchronouslyWithCompletionHandler 调用上的 AVAssetExportSession 访问错误
【发布时间】:2011-10-21 16:30:55
【问题描述】:

我正在尝试使用以下代码修剪视频:

        AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@.mp4",documentsDirectory,name]] options:nil]; 


    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
    NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@/finalOutput.mp4",documentsDirectory]];
    exportSession.outputURL = url;

    NSLog(@"outputting to: %@", [NSString stringWithFormat:@"%@/finalOutput.mp4",documentsDirectory,name]);
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    CMTimeRange timeRange = CMTimeRangeMake(flashbackStart, CMTimeSubtract(flashbackEnd, flashbackStart));
    exportSession.timeRange = timeRange;

    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        switch (exportSession.status) {
            case AVAssetExportSessionStatusCompleted:
                // Custom method to import the Exported Video
                //[self loadAssetFromFile:exportSession.outputURL];
                NSLog(@"completed!!!");
                break;
            case AVAssetExportSessionStatusFailed:
                //
                NSLog(@"Failed:%@",exportSession.error);
                break;
            case AVAssetExportSessionStatusCancelled:
                //
                NSLog(@"Canceled:%@",exportSession.error);
                break;
            default:
                break;
        }
    }];

但是,我收到此行的错误访问错误:

[exportSession exportAsynchronouslyWithCompletionHandler:^{

即使启用了 NSZombie,我也没有收到有关该错误的任何详细信息。谁能解释这里发生了什么?输入视频文件确实存在,而输出视频文件在我尝试写入之前不存在。

谢谢, 詹姆斯

【问题讨论】:

    标签: iphone avfoundation avassetexportsession


    【解决方案1】:

    原来问题出在我使用的NSURLs 上。我所要做的就是使用initFileURLWithPath,问题就解决了!

    【讨论】:

      【解决方案2】:

      您可能遇到了存储类型的问题。尝试将 __block 添加到您的 exportSession。

      __block AVAssetExportSession *exportSession...
      

      您可以在这里阅读更多内容:

      http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Blocks/Articles/bxGettingStarted.html#//apple_ref/doc/uid/TP40007502-CH7-SW5

      【讨论】:

      • 感谢您的回答,但没有任何影响。
      • 你是在问题中的代码之后发布 exportSession 吗?
      猜你喜欢
      • 1970-01-01
      • 2011-08-03
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 2013-08-13
      相关资源
      最近更新 更多