ios,Swift:如何将拆分的视频另存为一个视频拼贴

时间:2018-10-09 11:22:57

标签: ios iphone swift avfoundation swift4

我想制作一个视频拼贴,其中应在一个视图中显示2个或更多视频,然后可以将它们转换为一个视频文件。

Here is the rough idea about how my view controller looks now

//在这里,我有一个视频,根据视频的持续时间将其分为两部分。现在,我要将两个视频都保存在一个视频文件中作为拼贴。

import UIKit
import AVKit
import AVFoundation



class ViewController: UIViewController {
@IBOutlet weak var videoView: VideoView!
@IBOutlet weak var videoView2: VideoView!
var timer: Timer!
var tim:Double!
override func viewDidLoad() {
    super.viewDidLoad()
    let filePath = Bundle.main.path(forResource: "as", ofType: "mp4")

    videoView.configure(url: filePath!)
    videoView.isLoop = false
    videoView.play()
    let currentItem = videoView.player?.currentItem
    let duration = currentItem?.asset.duration
    videoView2.configure(url: filePath!)
    videoView2.isLoop = false
    videoView2.stop()
    tim = CMTimeGetSeconds(duration!)/2
    timer  = Timer.scheduledTimer(timeInterval:tim , target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: false)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@objc func runTimedCode() {
    videoView.stop()
    videoView2.player?.seek(to: CMTimeMake(Int64(Int(tim)), 1))
    videoView2.play()
  }
}

0 个答案:

没有答案