我正在尝试在 Mac 中使用 AVFoundation 创建两部连接电影的 QuickTime 参考电影。 以下是代码片段:
func mergeVideos(firstVideoURL: URL, secondVideoURL: URL, completion: @escaping (URL?, Error?) -> Void) {
let movie = AVMutableMovie(url: firstVideoURL)
let options = AVMovieWritingOptions.addMovieHeaderToDestination
do {
try? movie.insertTimeRange(CMTimeRange(start: .zero, duration: CMTime(seconds: 5, preferredTimescale: 600)), of: AVURLAsset(url: secondVideoURL), at: movie.duration, copySampleData: false)
let outputPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("mergedMovie.mov")
try movie.writeHeader(to: outputPath, fileType: .mov,options: options)
}catch {
print("\(error)")
}
}
我看到创建了 Samplereference 影片,当我打开它时,它没有显示视频,只显示黑框。感谢您对如何解决此问题有任何想法?
试过上面的代码,还是不行