How to reduce filter applying time to video in iOS?

时间:2018-12-03 12:52:19

标签: ios video avfoundation cifilter

Recording video using AVFoundation then applying filters to recorded video, filters also working fine. But it's taking 30 to 40 seconds time to convert video with filters. Is it possible to reduce filter applying time to video?

Thanks in advance.

dispatch_async(dispatch_get_main_queue(), ^{
AVURLAsset *asset = [AVURLAsset assetWithURL:videoURL];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoCompositionWithAsset:asset applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest * _Nonnull request) {
        [filter setDefaults];
        [filter setValue:request.sourceImage forKey:kCIInputImageKey];
        CIImage *outputImage = filter.outputImage;
        [request finishWithImage:outputImage context:nil];
    }];

 NSURL *outputFileURL = [NSURL fileURLWithPath:[self getDocumentsUrlForFilterMovie]];

    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset960x540];
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    exportSession.outputURL = outputFileURL;
    exportSession.videoComposition = videoComposition;
    exportSession.shouldOptimizeForNetworkUse = YES;

    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            switch (exportSession.status) {
                case AVAssetExportSessionStatusCompleted:

                    break;

                default:

                    break;
            }
        });
    }];
});

0 个答案:

没有答案