OStack程序员社区-中国程序员成长平台

标题: ios - GPUImage2 - 如何获取处理后的视频 URL 以保存在设备中? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:51
标题: ios - GPUImage2 - 如何获取处理后的视频 URL 以保存在设备中?

在应用视频过滤器后,谁能帮我从 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)")
}

提前致谢, 詹姆斯



Best Answer-推荐答案


 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()
       }
  })

关于ios - GPUImage2 - 如何获取处理后的视频 URL 以保存在设备中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49298598/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4