Latest 1.0
Homepage https://github.com/Tulakshana/Composer
License MIT
Platforms ios 9.0
Authors

Composer will help you to merge and crop video and audio. It can also make a video out of images.

Few use cases of Composer are as follows,

  • Merge video and audio files into one video
  • Make a video out of images. You can also tell how long it should display a particular image.
  • Add a background audio track to a video/videos and make it loop
  • Create thumbnails for videos
  • Trim video
  • Trim audio

Composer uses AVFoundation to make the above possible.

Usage

  1. Merge video and audio files into one video
        let video1: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_1", ofType: "mp4")!))
        let video2: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_2", ofType: "mp4")!))
        let video3: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_3", ofType: "mp4")!))

        let audio1: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio1", ofType: "wav")!))
        let audio2: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio2", ofType: "wav")!))
        let audio3: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio3", ofType: "wav")!))
        let audio4: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio4", ofType: "mp3")!))

        let track1 = Audio(start: 0, asset: audio1, ownTrackRequired: false)
        let track2 = Audio(start: 0, asset: audio2, ownTrackRequired: false)
        let track3 = Audio(start: 0, asset: audio3, ownTrackRequired: false)
        let track4 = Audio(start: 0, asset: audio4, ownTrackRequired: false)
        let track5 = Audio(start: 0, asset: audio1, ownTrackRequired: false)

        // Optionally specifiy a start time to an Audio and tell that it requires its own track if you want to play more than one audio track at the same time

        Composer.compose(videos: [video1, video2, video3], audios: [track1, track2, track3, track4, track5]) { (url: URL?) in
            // Composer has already switched to the main thread when it reaches here
            // url will point to file output. You may use an AVPlayer for playback
        }
  1. Make a video out of images
        var frames: [Frame] = []

        for i in 1...4 {
            let f = Frame.init(image: UIImage.init(named: "image(i)")!, duration: Double(i))
            frames.append(f)
        }

        Composer.compose(frames: frames) { (url: URL?) in
            // Composer has already switched to the main thread when it reaches here
            // url will point to file output. You may use an AVPlayer for playback
        }
  1. Add a background audio track to a video/videos and make it loop
        let video1: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_1", ofType: "mp4")!))
        let video2: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_2", ofType: "mp4")!))
        let video3: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_3", ofType: "mp4")!))
        let video4: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_4", ofType: "mp4")!))

        let audio1: AVAsset = AVAsset.init(url: URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio1", ofType: "wav")!))
        let track1 = Audio(start: 0, asset: audio1, ownTrackRequired: false)

        Composer.compose(videos: [video1, video2, video3, video4], audio: track1) { (url: URL?) in
             // Composer has already switched to the main thread when it reaches here
             // url will point to file output. You may use an AVPlayer for playback
        }
  1. Create thumbnails for videos
        url = URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_3", ofType: "mp4")!)
        let video: AVAsset = AVAsset.init(url: url!)
        thumbView.image = Composer.fetchThumbnail(video: video)
  1. Trim video
        url = URL.init(fileURLWithPath: Bundle.main.path(forResource: "sample_video_3", ofType: "mp4")!)

        let from = Double(txtFrom.text ?? "0") ?? 0.0 // value is expected in seconds
        let to = Double(txtTo.text ?? "0") ?? 0.0 // value is expected in seconds

        Composer.trimMedia(sourceURL: url!, from: from, to: to, completionHandler: { (url: URL?) in
             // Composer has already switched to the main thread when it reaches here
             // url will point to file output. You may use an AVPlayer for playback
        })
  1. Trim audio
        url = URL.init(fileURLWithPath: Bundle.main.path(forResource: "background_audio1", ofType: "wav")!)

        let from = Double(txtFrom.text ?? "0") ?? 0.0 // value is expected in seconds
        let to = Double(txtTo.text ?? "0") ?? 0.0 // value is expected in seconds

        Composer.trimMedia(sourceURL: url!, from: from, to: to, completionHandler: { (url: URL?) in
             // Composer has already switched to the main thread when it reaches here
             // url will point to file output. You may use an AVPlayer for playback
        })

License

Composer is available under the MIT license. See the LICENSE file for more info.

Todo:

  • Add transition effects
  • Deal with videos of different resolutions and frame rates

Latest podspec

{
    "name": "Composer",
    "version": "1.0",
    "summary": "Composer will help you to merge and crop video and audio. It can also make a video out of images.",
    "description": "Few use cases of Composer are as follows,n- Merge video and audio files into one videon- Make a video out of images. You can also tell how long it should display a particular image.n- Add a background audio track to a video/videos and make it loopn- Create thumbnails for videosnnComposer uses AVFoundation to make the above possible.nnTodo:n- Add transition effectsn- Deal with videos of different resolutions and frame rates",
    "license": "MIT",
    "authors": {
        "Tula": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.0",
    "source": {
        "git": "https://github.com/Tulakshana/Composer.git",
        "tag": "1.0"
    },
    "homepage": "https://github.com/Tulakshana/Composer",
    "source_files": [
        "Composer",
        "Composer/**/*.{h,m,swift}"
    ]
}

Pin It on Pinterest

Share This