[英]GPUImage2 - How to Get Processed Video URL To Save in Device?
有人在應用視頻過濾器后請幫助我從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)")
}
預先感謝,詹姆斯
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)
}
}
}
使用范例
applyFilters()
DispatchQueue.main.asyncAfter(deadline:.now()+AVAsset(url:inputVideoUrl).duration.seconds, execute: {
stopVideoRecording{
self.saveVideo()
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.