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

解決策を得ました。エクスポート セッションが初期化されていない場合、コントロールは完了ハンドラー内に移動しません。そのために、エクスポート セッションが null でないかどうかの条件チェックと、完了ハンドラーに進むことができます。私の場合、初期化されていなかったため、完了ブロック内に入っていませんでした。

于 2013-07-23T09:44:52.010 に答える