Closed ibhavin closed 6 years ago
Could you provide more details about 2 videos "gif2vid.mp4" and "mergedVideo.mp4" ? (dimension). I can still merge 2 mp4 videos normally.
@khoavd-dev
Basically I am converting a gif to video file from this ref. link: https://gist.github.com/powhu/00acd9d34fa8d61d2ddf5652f19cafcf and after that I am merging that video to other normal video.
Here are the samples of videos: http://www.yourfilelink.com/get.php?fid=1472967 http://www.yourfilelink.com/get.php?fid=1472968
The gif-to-video file is too short (0.4s), I guess that's the problem. Have you tried the gif-to-video file with duration over 1 second ?
@khoavd-dev
Yes, I have also tried with gif-to-video file which is about 6 second long.
http://www.yourfilelink.com/get.php?fid=1472983
let data = try! Data(contentsOf: Bundle.main.url(forResource: "giphy3", withExtension: "gif")!)
let tempUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("bean.mp4")
GIF2MP4(data: data)?.convertAndExport(to: tempUrl, completion: {
print("=========================")
print("Completed...")
let asset1 = AVAsset(url: tempUrl)
let asset2 = AVAsset(url: single_Image_Video_Url!)
KVVideoManager.shared.mergeWithAnimation(arrayVideos: [asset1, asset2], completion: { (final_Output, error) in
print("=========================")
print("final_Output:=",final_Output as Any)
print("Error:=",error?.localizedDescription ?? "")
})
})
Ahh, I found out that your videos have no sound. We can't export video without sound track. I fixed that issue by adding silence sound. Please pull source code again.
@khoavd-dev can you tell me how to repeat audio if video length is greater than audio length while merging video with audio?
@ibhavin you can compare the audio length and video length, then insert the corresponding time range for audio track:
try audioCompositionTrack?.insertTimeRange(CMTimeRangeMake(startTime, duration), of: audioTrack, at: insertTime)
All you need is to find out the correct value for startTime and duration
I am merging two videos with this code:
It prints final_URL but video is not available there. It prints error:
Cannot Open