2

我想修剪视频,为此我正在使用 AVExport 会话并将其时间范围属性设置为修剪视频。但问题是控件没有进入完成块。我使用了以下代码。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSFileManager *manager = [NSFileManager defaultManager];

NSString *outputURL = [documentsDirectory stringByAppendingPathComponent:@"output"] ;
[manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];

outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
// Remove Existing File
[manager removeItemAtPath:outputURL error:nil];    


AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];    

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.outputFileType = AVAssetExportPresetAppleM4A;
    CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(start, 1), CMTimeMake(end - start, 1));
exportSession.timeRange = timeRange;

[exportSession exportAsynchronouslyWithCompletionHandler:^{

    NSLog(@"Hi there inside completion handler");
    switch (exportSession.status) {
        case AVAssetExportSessionStatusCompleted:
            // Custom method to import the Exported Video
            [self exportDidFinish:exportSession];
            break;
        case AVAssetExportSessionStatusFailed:
            //
            NSLog(@"Failed:%@",exportSession.error);
            break;
        case AVAssetExportSessionStatusCancelled:
            //
            NSLog(@"Canceled:%@",exportSession.error);
            break;
        default:
            break;
    }
}];

请帮我解决这个问题。

4

1 回答 1

0

得到了解决方案。如果未初始化导出会话,则控件不会进入完成处理程序。为此,如果导出会话不为空,您可以进行条件检查,然后在完成处理程序中继续。就我而言,它没有被初始化,这就是它没有进入完成块的原因。

于 2013-07-23T09:44:52.010 回答