Kakapos is a high-performance, flexible video editing and exporting framework designed for iOS, macOS, watchOS, and tvOS. It provides a powerful set of tools for adding filters, watermarks, rotations, and other effects to videos from various sources including network URLs, local files, and album videos.
- Multi-source Support: Process videos from network URLs, local files, and album assets
- Filter Integration: Compatible with multiple filter frameworks:
- CoreImage
- Harbeth (Metal-based filter framework)
- GPUImage
- MetalPetal
- BBMetalImage
- Any custom filter framework that converts CVPixelBuffer
- Comprehensive Instructions: Built-in support for:
- Filter application with time-based control
- Text and image watermarks with customizable positioning
- Video rotation (90Β°, 180Β°, 270Β°)
- Custom instruction creation for extended functionality
- High Performance: Optimized for speed and efficiency using Metal where available
- Flexible Export Options: Customizable export settings including time range, quality, and network optimization
- Easy to Use: Simple API with clear instruction-based architecture
- Extensible: Create custom instructions for your specific video processing needs
- Performance Focused: Leverages hardware acceleration for fast processing
- Versatile: Supports a wide range of video sources and filter frameworks
- Well Documented: Comprehensive documentation and example code
Kakapos uses an instruction-based architecture where you define a series of processing steps (instructions) that are applied to each video frame. These instructions are processed in sequence, allowing for complex video transformations with minimal code.
The framework handles the heavy lifting of video frame processing, leaving you free to focus on creating the desired visual effects.
- Create the video exporter provider.
let exporter = VideoX.init(provider: .init(with: ``URL Link``))
Or
let exporter = VideoX.init(provider: .init(with: ``AVAsset``))
- Create filter instruction and add filters.
let filters1: [C7FilterProtocol] = [
C7LookupTable(name: "lut_abao"),
C7SplitScreen(type: .two),
C7Mirror(),
C7Contrast(contrast: 0.9),
C7SoulOut(soul: 0.3),
]
let filters2: [C7FilterProtocol] = [
C7Flip(horizontal: true, vertical: true),
C7SoulOut(soul: 0.3),
]
let filtering = FilterInstruction { buffer, time, callback in
if time >= 0, time < 3 {
buffer.kaka.filtering(with: filters1, callback: callback)
} else {
let dest = HarbethIO(element: buffer, filters: filters2)
dest.transmitOutput(success: callback)
}
}
- Create a watermark instruction.
let textWatermark = WatermarkInstruction(
type: .text("Kakapos", font: .boldSystemFont(ofSize: 120), color: .red),
position: .bottomRight,
margin: 20,
opacity: 0.8,
)
- Create a rotate instruction.
let rotateInstruction = RotateInstruction(rotationAngle: selectedRotation)
- Convert video and then convert buffer.
let exporter = VideoX.init(provider: provider)
/// Export the video.
/// - Parameters:
/// - options: Setup other parameters about export video.
/// - instructions: Operation procedure.
/// - complete: The conversion is complete, including success or failure.
exporter.export(options: [
.OptimizeForNetworkUse: true,
.ExportSessionTimeRange: TimeRangeType.range(5...28.0),
], instructions: [filtering, textWatermark, rotateInstruction], complete: { res in
// do somthing..
}, progress: { pro in
// progressing..
})
You can create your own custom instructions by following these steps:
- Create a calss that conforms to the
InstructionProtocol&Instruction - Use your custom instruction
public class BrightnessInstruction: CompositionInstruction {
public let timeRange: CMTimeRange
public let brightness: Float
public init(brightness: Float, timeRange: CMTimeRange = .init(start: .zero, duration: .positiveInfinity)) {
self.brightness = brightness
self.timeRange = timeRange
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func operationPixelBuffer(_ buffer: CVPixelBuffer, block: @escaping BufferBlock, for request: AVAsynchronousVideoCompositionRequest) {
if let brightnessBuffer = processBrightness(buffer) {
block(brightnessBuffer)
}
}
func processBrightness(_ pixelBuffer: CVPixelBuffer) -> CVPixelBuffer? {
// Implement brightness adjustment logic
// This could use CoreImage, Harbeth, or other frameworks
return pixelBuffer
}
}By following this pattern, you can create any custom video processing instructions you need.
Such as:
- Color adjustment instructions
- Special effects instructions
- Text overlay instructions
- Audio processing instructions
- And more!
- 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 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"),
]The general process is almost like this, the Demo is also written in great detail, you can check it out for yourself.π·
Tip: If you find it helpful, please help me with a star. If you have any questions or needs, you can also issue.
Thanks.π
- π· E-mail address: yangkj310@gmail.com π·
- πΈ GitHub address: yangKJ πΈ
Buy me a coffee or support me on GitHub.
Alipay or WeChat. Thanks.
Harbeth is available under the MIT license. See the LICENSE file for more info.


