CoreImageというframeworkを使って静止画・動画にフィルターをかけたいと思っています。
静止画に関しては、CIfilterを用いてフィルターをかけることができたのですが、動画については調べたところ、'AVAsynchronousCIImageFilteringRequest'というクラスを用いてCIFilterをかける方法が公式サイトにありました。
Apple Developer
swift
1let filter = CIFilter(name: "CIGaussianBlur")! 2let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in 3 4 // Clamp to avoid blurring transparent pixels at the image edges 5 let source = request.sourceImage.imageByClampingToExtent() 6 filter.setValue(source, forKey: kCIInputImageKey) 7 8 // Vary filter parameters based on video timing 9 let seconds = CMTimeGetSeconds(request.compositionTime) 10 filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey) 11 12 // Crop the blurred output to the bounds of the original image 13 let output = filter.outputImage!.imageByCroppingToRect(request.sourceImage.extent) 14 15 // Provide the filter output to the composition 16 request.finishWithImage(output, context: nil) 17})
AppleDeveloperでは上記を例にAVAssetにCIFilterをかける方法が載っていたのですが、ここからこのAVVideoCompositionを再びAVAssetに変換する方法がわかりません。
どなたかわかる方がいらっしゃれば是非教えて頂きたいです。
よろしくお願いいたします。
あなたの回答
tips
プレビュー