MediaToolSwift 1.2.0

MediaToolSwift 1.2.0

Maintained by starkdev.



  • By
  • Dmitry Starkov

MediaToolSwift

Advanced media converter for iOS, macOS and tvOS

Video

Video compressor focused on:

  • Multiple video and audio codecs
  • Lossless
  • HDR content
  • Alpha channel
  • Slow motion
  • Metadata
  • Hardware Acceleration
  • Progress and cancellation

Features

Convert Resize Crop Cut Rotate, Flip, Mirror Image Processing* FPS Thumbnail Info
✔️ ✔️ ✔️ ⭐️ ⭐️ ✔️ ✔️ ✔️ 🚧

⭐️ - do not require re-encoding (lossless)

Supported video codecs:

  • H.264
  • H.265/HEVC
  • ProRes
  • JPEG

Additionally decoding is supported for: H.263, MPEG-1, MPEG-2, MPEG-4 Part 2

Supported audio codecs:

  • AAC
  • Opus
  • FLAC
  • Linear PCM
  • Apple Lossless

Example:

// Run video compression
let task = await VideoTool.convert(
    source: URL(fileURLWithPath: "input.mp4"),
    destination: URL(fileURLWithPath: "output.mov"),
    // Video
    fileType: .mov, // mov, mp4, m4v
    videoSettings: .init(
        codec: .hevc,
        bitrate: .value(2_000_000), // optional
        size: .hd, // CGSize to aspect fit in
        // quality, fps, alpha channel, profile, color primary, atd.
        edit: [
            .cut(from: 2.5, to: 15.0), // cut, in seconds
            .rotate(.clockwise), // rotate
            // crop, flip, mirror, atd.

            // modify video frames as images
            .imageProcessing { image, _, _ in
                image.applyingFilter("CIGaussianBlur", parameters: [
                    "inputRadius": 7.5
                ])
            }
        ]
    ),
    optimizeForNetworkUse: true,
    // Audio
    skipAudio: false,
    audioSettings: .init(
        codec: .opus,
        bitrate: .value(96_000)
        // quality, sample rate, volume, atd.
    ),
    // Metadata
    skipSourceMetadata: false,
    customMetadata: [],
    copyExtendedFileMetadata: true,
    // File options
    overwrite: false,
    deleteSourceFile: false,
    // State notifier
    callback: { state in
        switch state {
        case .started:
            print("Started")
        case .progress(let progress):
            print("Progress: \(progress.fractionCompleted)")
        case .completed(let url):
            print("Done: \(url.path)")
        case .failed(let error):
            print("Error: \(error.localizedDescription)")
        case .cancelled:
            print("Cancelled")
        }
})

// Cancel the compression
task.cancel()

Complex example can be found in this directory.

Requirements

  • macOS 11.0+
  • iOS 13.0+
  • tvOS 13.0+

Installation

Swift Package Manager

To install library with Swift Package Manager, add the following code to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/starkdmi/MediaToolSwift.git", .upToNextMajor(from: "1.0.7"))
]

CocoaPods

To install library with CocoaPods, add the following line to your Podfile file:

pod 'MediaToolSwift', :git => 'https://github.com/starkdmi/MediaToolSwift.git', :version => '1.0.7'

Documentation

Swift DocC documentation is hosted on Github Pages

More info on video features and operations can be found here.