Giter Site home page Giter Site logo

hyperclip's Introduction

MergeVideos

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

Features

  • Merge videos.
  • Merge videos with transition animation.
  • Add background music to a video.
  • Merge videos and images with transition animation.
  • Add text with fade in / fade out animation into a video.

Requirements

  • iOS 13.0+
  • Xcode 13.0+
  • Swift 5+

Updates

20/10/2021

  • Update source code to run on Xccode 13 and Swift 5.
  • Refactor code.
  • Fix issue: merging videos shows black screen sometimes. (update videoCompositionInstructionForTrack function)

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).

  • Merge videos
let videoAsset1 = AVAsset(url: urlVideo1)
let videoAsset2 = AVAsset(url: urlVideo2)
        
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
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)")
           }
     }
}
  • Add background music to a video
let videoAsset = AVAsset(url: urlVideo)
let musicAsset = AVAsset(url: urlMusic)
        
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
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 !!!

hyperclip's People

Contributors

khoavd-dev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.