在应用视频过滤器后,有人请帮我从GPUImage2 Library获取处理过的视频网址吗?
do {
let bundleURL = Bundle.main.resourceURL!
let movieURL = URL(string:"sample_iPod.m4v", relativeTo:bundleURL)!
movie = try MovieInput(url:movieURL, playAtActualSpeed:true)
filter = SaturationAdjustment()
movie --> filter --> renderView
movie.start()
} catch {
fatalError("Could not initialize rendering pipeline: \(error)")
}
先谢谢, 詹姆斯
答案 0 :(得分:0)
func applyfilters(){
do {
// movie input
movieInput = try MovieInput(url: inputVideoUrl, playAtActualSpeed: true, loop: false)
// movie output
movieOutput = try MovieOutput(URL: outputVideoUrl, size: videoSize, liveVideo: false)
// pipeline
movieInput.addTarget(currentFilter)
currentFilter.addTarget(renderView)
currentFilter.addTarget(movieOutput!)
movieOutput!.startRecording()
movieInput.start()
} catch {
print(error.localizedDescription)
}
}
//Below function should be called after the filter is applied on full video. If you call this function before video ends it will not generate the rest part of the video.
func stopVideoRecording(completion: (() -> Void)?) {
movieOutput?.finishRecording {
completion?()
}
}
//To save video
func saveVideo(){
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputVideoUrl)
}) { saved, error in
if saved {
let alertController = UIAlertController(title: "Your video was successfully saved", message: nil, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
Usage Example
applyFilters()
DispatchQueue.main.asyncAfter(deadline:.now()+AVAsset(url:inputVideoUrl).duration.seconds, execute: {
stopVideoRecording{
self.saveVideo()
}
})