/Kakapos

πŸŒ€ Video export tool, Support Harbeth, CoreImage or GPUImage and so on.

Primary LanguageSwiftMIT LicenseMIT

Kakapos

CocoaPods Compatible Platform

Kakapos is a video add filter tool that supports network and local urls, as well as album videos.

Support macOS, iOS, tvOS and watchOS.


Used

  • Set the conversion video storage sandbox link.
// Creating temp path to save the converted video
let outputURL: URL = {
    let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
    let outputURL = documents.appendingPathComponent("condy_exporter_video.mp4")
    
    // Check if the file already exists then remove the previous file
    if FileManager.default.fileExists(atPath: outputURL.path) {
        do {
            try FileManager.default.removeItem(at: outputURL)
        } catch {
            //completionHandler(nil, error)
        }
    }
    return outputURL
}()
  • Create the video exporter instance.
let exporter = Exporter.init(videoURL: ``URL Link``, delegate: self)

Or

let exporter = Exporter.init(asset: ``AVAsset``, delegate: self)
  • Implement the agreement ExporterDelegate.
/// Video export successed.
/// - Parameters:
///   - exporter: VideoExporter
///   - videoURL: Export the successful video url, Be equivalent to outputURL.
func export(_ exporter: Kakapos.Exporter, success videoURL: URL) {
    self.view.hideAllToasts()
    let player = AVPlayer(url: videoURL)
    let vc = AVPlayerViewController()
    vc.player = player
    self.present(vc, animated: true) {
        vc.player?.play()
    }
}

/// Video export failure.
/// - Parameters:
///   - exporter: VideoExporter
///   - error: Failure error message.
func export(_ exporter: Kakapos.Exporter, failed error: Kakapos.Exporter.Error) {
    // do someing..
}
  • Convert video and add filters, convert buffer.
let filters: [C7FilterProtocol] = [
    C7Flip(horizontal: true, vertical: false),
    C7ColorConvert(with: .gray),
    C7SoulOut(soul: 0.3),
    MPSGaussianBlur(radius: 5),
]

/// Export the video after injecting the filter.
/// - Parameters:
///   - outputURL: Specifies the sandbox address of the exported video.
///   - optimizeForNetworkUse: The output file should be optimized for network use.
///   - filtering: Filters work to filter pixel buffer.
exporter.export(outputURL: outputURL) {
    let dest = BoxxIO(element: $0, filters: filters)
    return try? dest.output()
}

Or

exporter.export(outputURL: outputURL) { $0 ->> gauss ->> board }

CocoaPods

  • If you want to import video exporter module, you need in your Podfile:
pod 'Kakapos'
  • If you want to import metal filter module, you need in your Podfile:
pod 'Harbeth'

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Xcode 11+ is required to build Kakapos using Swift Package Manager.

To integrate Harbeth into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/yangKJ/Kakapos.git", branch: "master"),
]

Remarks

The general process is almost like this, the Demo is also written in great detail, you can check it out for yourself.🎷

KakaposDemo

Tip: If you find it helpful, please help me with a star. If you have any questions or needs, you can also issue.

Thanks.πŸŽ‡

About the author


License

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