I want to filter selected video from Photos so use CIFilter and AVVideoComposition but it take too much time.
it take 3 minute for 30 second video.
How to reduce time for filter.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
[self dismissViewControllerAnimated:YES completion:nil];
NSURL *videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
AVAsset *asset = [AVAsset assetWithURL:videoUrl];
AVVideoComposition *composition = [AVVideoComposition videoCompositionWithAsset:asset applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest * _Nonnull request) {
CIImage *ciImage = request.sourceImage.imageByClampingToExtent;
[filter setValue:ciImage forKey:kCIInputImageKey];
Float64 seconds = CMTimeGetSeconds(request.compositionTime);
[filter setValue: @(seconds * 10.0) forKey:kCIInputRadiusKey];
CIImage *outputImage = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent];
[request finishWithImage:outputImage context:nil];
}];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"];
unlink([pathToMovie UTF8String]);
NSURL *outputUrl = [NSURL fileURLWithPath:pathToMovie];
AVAssetExportSession *export = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
export.outputFileType = AVFileTypeQuickTimeMovie;
export.outputURL = outputUrl;
export.videoComposition = composition;
[export exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"Video Output url : %@", outputUrl.absoluteString);
}];
}