ImageSequencer

0.2

A well-tested iOS framework for producing a video from a sequence of images.
samst-one/ImageSequencer

What's New

0.2

2024-03-28T18:44:24Z

Release of 0.2

ImageSequencer

A badge showing Swift compatibility, currently 5.8 A badge showing compatibility with Apple platforms. Currently compatible with iOS, macOS and tvOS.

Overview

ImageSequencer is a Swift framework for iOS, macOS, tvOS that allows you to create videos from a selection of images. Developed by Sam Stone.

In use in production with Lapsey. Create beautiful time-lapses on iOS - find out more here.

The API can be found in the ImageSequencerController interface.

Install

Go to File > Swift Packages > Add Package Dependency and add the following URL:

https://github.com/samst-one/ImageSequencer

Usage

  1. First we need to import the ImageSequencer into our project, we do this by importing the framework
import ImageSequencer
  1. Next we need to create a ImageSequencerController object. The ImageSequencerController acts as the API for the package. We use the ImageSequencerFactory to do this. We also pass in the settings for the video we want to create. To create the ImageSequencerController, we do:
let outputUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("\(UUID().uuidString).mp4")

let renderSettings = RenderSettings(bitrate: 10000000,
                                    size: CGSize(width: 1920,
                                    height: 1080),
                                    fps: 24,
                                    outputUrl: outputUrl)

let controller = try? ImageSequencerFactory.make(settings: settings)

The make method has the ability to throw.

  1. With the controller, we can now access the API. We first must start of some internal ImageSequencer processes before rendering. To do this, call:
controller.start()
  1. When you have the images you want to render to a video, we can call the render function below. A breakdown of the parameters are as follows.

    • Parameters:
      • images: The collection of images you wish to render in URL format.
      • didAddFrame: A closure that returns a double representing the percentage of rendering completed.
      • completion: A closure thats called when all the images have been rendered out. It returns an optional Error.

So the code looks a bit like this:

controller?.render(images:  images) { percent in

} completion: { error in
                
}
  1. Once the completion handler has been called without an error, you call the finish() method to produce the video. The video can be found at the output URL that was provided in the render settings.
controller?.finish { outputUrl in
// Video now available at output URL provided.
}

Putting it all together

In conclusion, to render out an sequence of images, use full code is below:

let outputUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("\(UUID().uuidString).mp4")

let renderSettings = RenderSettings(bitrate: 10000000,
                                    size: CGSize(width: 1920,
                                    height: 1080),
                                    fps: 24,
                                    outputUrl: outputUrl)

let controller = try? ImageSequencerFactory.make(settings: settings)
controller?.start()
    
controller?.render(images:  images) { percent in
    // Update the user on progress here.
} completion: { error in
    if error == nil {
        controller?.finish { outputUrl in
            // Video now available at output URL provided.
        }
    }
}

A sample app is included.

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Apr 13 2024 14:07:02 GMT-0900 (Hawaii-Aleutian Daylight Time)