I am trying to create an QuickTime reference movie of two joined movies using AVFoundation in Mac. Following is the code snipped :
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)")
}
}
I see that the Samplereference movie gets created and when I open it does not show up video and shows only black frame. Appreciate any thoughts on how to fix this?