CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

MTMedia 1.0.0

MTMedia 1.0.0

Maintained by MiTu.



MTMedia 1.0.0

  • By
  • Mitu Ultra

MTMedia

Version License Platform

About

HI, MTMedia is a powerful Swift library designed as a temporary replacement for FFmpeg and FFprobe in your iOS projects. If you're looking for a tool to process and analyze media (such as videos and audio) but cannot yet use the official FFmpeg libraries, MTMedia provides the perfect solution. 🚀

Editing Demo 🎬

Installation with CocoaPods

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

target 'MyApp' do
  pod 'MTMedia'
end

Swift Package Manager

Once you have your Swift package set up, adding MTMedia as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/hominhtuong/MTMedia.git", .upToNextMajor(from: "1.0.0"))
]

Example code:

The code would look like this:
    func mergeVideo() async -> URL? {
        guard
            let videoUrl = Bundle.main.url(
                forResource: "video",
                withExtension: "mp4"
            ),
            let imageUrl = Bundle.main.url(
                forResource: "cover",
                withExtension: "jpeg"
            )
        else {
            printDebug("Cannot find video or image")
            return nil
        }

        guard
            let outputUrl = cacheURL?.appendingPathComponent(
                "\(Date().timeIntervalSince1970).mp4"
            )
        else {
            printDebug("Cannot create output url")
            return nil
        }

        let command =
            "-i \(videoUrl.getPath) -i \(imageUrl.getPath) -filter_complex \"[1:v]scale=1280:720[img];[0:v][img]overlay=0:0:enable='between(t,0,2)'\" -c:a copy \(outputUrl.getPath)"

        guard let session = await MTMedia.execute(command) else {
            return nil
        }

        if session.isSuccess() {
            return await video2GIF(inputUrl: outputUrl)
        } else {
            return nil
        }
    }

    func video2GIF(inputUrl: URL) async -> URL? {
        guard
            let outputUrl = cacheURL?.appendingPathComponent(
                "\(Date().timeIntervalSince1970).gif"
            )
        else {
            printDebug("Cannot create output url")
            return nil
        }
        let command =
            "-i \(inputUrl.getPath) -vf \"fps=20,scale=640:360:flags=lanczos\" -c:v gif \(outputUrl)"

        guard let session = await MTMedia.execute(command) else {
            return nil
        }

        return session.isSuccess() ? outputUrl : nil
    }

    

License

MTMedia is released under the MIT license. See LICENSE for more details.

My website: Visit