GPUImage2 - 如何获取已处理的视频URL以保存在设备中?

问题描述 投票:2回答:1

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

先谢谢你,詹姆斯

ios swift gpuimage
1个回答
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)
        }
    }
 }

用法示例

  applyFilters()

  DispatchQueue.main.asyncAfter(deadline:.now()+AVAsset(url:inputVideoUrl).duration.seconds, execute: {
       stopVideoRecording{
            self.saveVideo()
       }
  })
© www.soinside.com 2019 - 2024. All rights reserved.