[英]GPUImage2 - How to Get Processed Video URL To Save in Device?
Anyone please help me to get the processed video URL from GPUImage2 Library after applying video filter? 有人在应用视频过滤器后请帮助我从GPUImage2库获取经过处理的视频URL?
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)")
}
Thanks in Advance, James 预先感谢,詹姆斯
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()
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.