1

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

        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,我也没有得到有关该错误的任何详细信息。谁能解释这里发生了什么?输入视频文件确实存在,并且在我尝试写入之前输出视频文件不存在。

谢谢,詹姆斯

4

2 回答 2

2

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

于 2011-10-21T18:21:02.083 回答
1

您可能会遇到存储类型的问题。尝试将 __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

于 2011-10-21T16:36:25.157 回答