khoavd-dev / MergeVideos

A demo about merging videos & images in iOS
MIT License
110 stars 29 forks source link
ios ios-demo ios-swift merging swift swift4 videos

MergeVideos

This is a sample implementation for merging multiple videos and/or images using AVFoundation, fixed orientation issues.

Features

Requirements

Updates

20/10/2021

Usage

Drag the files in VideoManager folder into your project.

Please refer to the sample project MergeVideos for more details. (Don't forget to run pod install before opening the project).

KVVideoManager.shared.merge(arrayVideos: [videoAsset1, videoAsset2]) { (outputURL, error) in if let error = error { print("Error:(error.localizedDescription)") } else { if let url = outputURL { print("Output video file:(url)") } } }

- Merge videos with transition animation
```swift
let videoAsset1 = AVAsset(url: urlVideo1)
let videoAsset2 = AVAsset(url: urlVideo2)

KVVideoManager.shared.mergeWithAnimation(arrayVideos: [videoAsset1, videoAsset2]) { (outputURL, error) in
      if let error = error {
           print("Error:\(error.localizedDescription)")
      }
      else {
           if let url = outputURL {
               print("Output video file:\(url)")
           }
     }
}

KVVideoManager.shared.merge(video:videoAsset, withBackgroundMusic:musicAsset) { (outputURL, error) in if let error = error { print("Error:(error.localizedDescription)") } else { if let url = outputURL { print("Output video file:(url)") } } }

- Merge videos and images and text with transition animation
```swift
let videoData = VideoData()
videoData.isVideo = true
videoData.asset = AVAsset(url: urlVideo)

let imageData = VideoData()
imageData.isVideo = false
imageData.image = UIImage(named: "sample-image")

let textData = TextData(text: "HELLO WORLD",
                        fontSize: 50,
                        textColor: UIColor.green,
                        showTime: 3,
                        endTime: 5,
                        textFrame: CGRect(x: 0, y: 0, width: 400, height: 300))

KVVideoManager.shared.makeVideoFrom(data: [videoData, imageData], textData: [textData]) { (outputURL, error) in
     if let error = error {
           print("Error:\(error.localizedDescription)")
      }
      else {
           if let url = outputURL {
               print("Output video file:\(url)")
           }
     }      
}

Note

This is a sample implementation to demonstrate the functions in AVFoundation with just some simple animations, but you got the idea !

You would be able to add more complicated transition animation, text showing animation by using Core Animation !!!