Giter VIP home page Giter VIP logo

datt1994 / dpvideomerger-swift Goto Github PK

View Code? Open in Web Editor NEW
57.0 7.0 20.0 18.09 MB

Multiple videos merge in one video with manage scale & aspect ratio and also merge videos to grid matrix layout for Swift.

Home Page: https://datt1994.github.io/DPVideoMerger-Swift/

License: Apache License 2.0

Swift 87.55% Ruby 11.45% Objective-C 1.00%
video-merger video-merge merging videos swift ios grid merger merge-videos swift5 video grid-layout matrix carthage xcode cocoapods dpvideomerger-swift

dpvideomerger-swift's Introduction

DPVideoMerger-Swift

Platform Language: Swift 5 License Version Carthage compatible

Sequence Parallel Grid
Sequence Parallel Grid

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C & Swift. You can install it with the following command:

$ gem install cocoapods

Podfile

To integrate DPVideoMerger into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target 'TargetName' do
use_frameworks!
pod 'DPVideoMerger-Swift'
end

Then, run the following command:

$ pod install

Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate DPVideoMerger-Swift into your Xcode project using Carthage, specify it in your Cartfile:

github "Datt1994/DPVideoMerger-Swift"

Run carthage to build the framework and drag the framework (DPVideoMerger_Swift.framework) into your Xcode project.

Installation with Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

To add the library as package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL https://github.com/Datt1994/DPVideoMerger-Swift.git

Add Manually

Download Project and copy-paste DPVideoMerger.swift file into your project

Usage

import AVKit

let fileURL = Bundle.main.url(forResource: "1", withExtension: "mp4")
let fileURL1 = Bundle.main.url(forResource: "2", withExtension: "mp4")
let fileURL2 = Bundle.main.url(forResource: "3", withExtension: "MOV")
let fileURL3 = Bundle.main.url(forResource: "4", withExtension: "mp4")
let fileURLs = [fileURL, fileURL1, fileURL2, fileURL3]


/// Multiple videos merge in one video with manage scale & aspect ratio
/// - Parameters:
///   - videoFileURLs: Video file path URLs, Array of videos that going to merge
///   - videoResolution: Output video resolution, (defult:  CGSize(width: -1, height: -1), find max width and height from provided videos)
///   - videoQuality: AVAssetExportPresetMediumQuality(default) , AVAssetExportPresetLowQuality , AVAssetExportPresetHighestQuality
///   - completion: Completion give  2 optional  values, 1)mergedVideoURL: URL path of successfully merged video   2)error: Gives Error object if some error occur in videos merging process
///   - mergedVideoURL: URL path of successfully merged video
///   - error: Gives Error object if some error occur in videos merging process
DPVideoMerger().mergeVideos(withFileURLs: fileURLs as! [URL], completion: {(_ mergedVideoFile: URL?, _ error: Error?) -> Void in
    if error != nil {
        let errorMessage = "Could not merge videos: \(error?.localizedDescription ?? "error")"
        let alert = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (a) in
        }))
        self.present(alert, animated: true) {() -> Void in }
        return
    }
    let objAVPlayerVC = AVPlayerViewController()
    objAVPlayerVC.player = AVPlayer(url: mergedVideoFile!)
    self.present(objAVPlayerVC, animated: true, completion: {() -> Void in
        objAVPlayerVC.player?.play()
    }) 
})


/// Merge  videos to grid matrix layout
/// - Parameters:
///   - videoFileURLs: Video file path URLs, Array of videos that going to grid merge
///   - matrix: Video matrix position (eg 3x3, 4x2, 1x3, ...) (default:- 2x2)
///   - audioFileURL: Optional audio file for Merged Video
///   - videoResolution: Output video resolution
///   - isRepeatVideo: Repeat Video on grid if one or more video have shorter duartion time then output video duration
///   - isRepeatAudio: Repeat Audio if Merged video have longer duartion time then provided Audio duration
///   - isAudio: Allow Audio for grid video (default :- true)
///   - videoDuration: Output video duration (defult:  -1, find max duration from provided  videos)
///   - videoQuality: AVAssetExportPresetMediumQuality(default) , AVAssetExportPresetLowQuality , AVAssetExportPresetHighestQuality
///   - completion: completion give  2 optional  values, 1)mergedVideoURL: URL path of successfully grid merged video  2)error: gives Error object if some error occur in videos merging process
///   - mergedVideoURL: URL path of successfully grid merged video
///   - error: gives Error object if some error occur in videos merging process
DPVideoMerger().gridMergeVideos(withFileURLs: fileURLs, videoResolution: CGSize(width: 1000, height: 1000), completion: {(_ mergedVideoFile: URL?, _ error: Error?) -> Void in
    if error != nil {
        let errorMessage = "Could not merge videos: \(error?.localizedDescription ?? "error")"
        let alert = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (a) in
        }))
        self.present(alert, animated: true) {() -> Void in }
        return
    }
    let objAVPlayerVC = AVPlayerViewController()
    objAVPlayerVC.player = AVPlayer(url: mergedVideoFile!)
    self.present(objAVPlayerVC, animated: true, completion: {() -> Void in
        objAVPlayerVC.player?.play()
    })
})

dpvideomerger-swift's People

Contributors

datt1994 avatar mattio avatar roger-blinto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dpvideomerger-swift's Issues

Eternal Audio Merge

Thank you very much for your amazing work.

I am merging external audio with parallel 2 videos. I can't able to add external audio in merging result video. Can you please guide me, How can i add external audio in merging result video. I am currently using parallelMergeVideos method.

Any help appreciated.

Wrong orientation on parallel and grid merge

When I call the Parallel or Grid merge methods passing videos recorded with my device's camera (iPhone 11 Pro), the resulting video shows the footage with wrong orientation.

For example: 2 portrait videos show rotated in landscape

Captura de Tela 2020-08-25 às 15 20 58

It only happens with videos recorded with the device's camera. Videos from the web appear in the correct orientation.

Android Video Merge

Can we get same type of video merge side by side in Android? can you help on this

Incorrect orientations after merge video

After merging two video, video orientation gets changed. I record two video in vertical mode and merge then it gets changed as horizontal on same device. This is i have tested on multiple device and find same behaviour.

After merging 2 video some frame is missing ,

Hello, First I would like to say thanks for creating a nice code for merging, I got one issue with that, Like when I am merging 2 videos some frames is got missing.

1> video duration is 5 seconds
2> video duration is 5 Second

After merging it duration should be 10 but it is showing only 8 seconds.
Could you please suggest to me what is I am doing missing?

How to arranged merged video in center position?

right now i am doing merged 2 video side by side using gridMergeVideos function, and it's almost worked but video top position is 0. how to fix this issue ? . here is my attach screenshot which is display two merged videos into one video. you can see in screenshot video top is start with 0 , how can i arranged merged video in center position ?

Simulator Screen Shot - iPhone 11 Pro Max - 2020-07-28 at 17 20 40

any help is appreciated

A video with multiple audio tracks loses the audio when merged

Hello! Thanks for this library!

I ran into a scenario where a video was being recorded with ReplayKit in custom fashion and it ended up having multiple audio tracks. When I merged that video with another, there was some audio loss.

I believe I found the place in the code that assumed a single audio track and updated it to allow for multiple. I'll submit a PR for the change that worked in my scenario. Hope you find it useful enough to merge!

Need help

I am using the camera preview and then startRecording from there, when I merge it with other videos it will be turn into landscape, but I want it portrait. Can you guide me how

How to use Assets video in this library

Hello,

I want to merge Photo library videos in single video.

Is your library support assets video merging ?

if Not any future plan to add this feature ?

Thanks in advance!

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.