菜鸟教程小白 发表于 2022-12-11 19:51:46

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


                                            <p><p>在应用视频过滤器后,谁能帮我从 GPUImage2 库中获取处理后的视频 URL?</p>

<pre><code>do {
    let bundleURL = Bundle.main.resourceURL!
    let movieURL = URL(string:&#34;sample_iPod.m4v&#34;, relativeTo:bundleURL)!
    movie = try MovieInput(url:movieURL, playAtActualSpeed:true)
    filter = SaturationAdjustment()
    movie --&gt; filter --&gt; renderView
    movie.start()
} catch {
    fatalError(&#34;Could not initialize rendering pipeline: \(error)&#34;)
}
</code></pre>

<p>提前致谢,
詹姆斯</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code> 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: (() -&gt; 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: &#34;Your video was successfully saved&#34;, message: nil, preferredStyle: .alert)
            let defaultAction = UIAlertAction(title: &#34;OK&#34;, style: .default, handler: nil)
            alertController.addAction(defaultAction)
            self.present(alertController, animated: true, completion: nil)
      }
    }
}
</code></pre>

<p><strong>使用示例</strong></p>

<pre><code>applyFilters()

DispatchQueue.main.asyncAfter(deadline:.now()+AVAsset(url:inputVideoUrl).duration.seconds, execute: {
       stopVideoRecording{
            self.saveVideo()
       }
})
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - GPUImage2 - 如何获取处理后的视频 URL 以保存在设备中?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/49298598/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/49298598/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - GPUImage2 - 如何获取处理后的视频 URL 以保存在设备中?