Kakapos
๐ High-performance and flexible video edit and export framework.
Install / Use
/learn @yangKJ/KakaposREADME
Kakapos
<img width=230px src="https://raw.githubusercontent.com/yangKJ/Kakapos/master/Screenshot/1.png" />๐ Overview
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.
โจ Key Features
- 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
๐ฏ Why Choose Kakapos?
- 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
๐ง How It Works
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.
Used
- 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..
})
Custom Instruction
You can create your own custom instructions by following these steps:
- Create a calss that conforms to the
InstructionProtocol&Instruction - Use your custom instruction
Example: Create a Brightness Adjustment 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!
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.๐ท
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
- ๐ท E-mail address: yangkj310@gmail.com ๐ท
- ๐ธ GitHub address: yangKJ ๐ธ
Buy me a coffee or support me on GitHub.
<a href="https://www.buymeacoffee.com/yangkj3102"> <img width=25% alt="yellow-button" src="https://user-images.githubusercontent.com/1888355/146226808-eb2e9ee0-c6bd-44a2-a330-3bbc8a6244cf.png"> </a>Alipay or WeChat. Thanks.
<p align="left"> <img src="https://raw.githubusercontent.com/yangKJ/Harbeth/master/Screenshot/WechatIMG1.jpg" width=30% hspace="1px"> <img src="https://raw.githubusercontent.com/yangKJ/Harbeth/master/Screenshot/WechatIMG2.jpg" width=30% hspace="15px"> </p>License
Harbeth is available under the MIT license. See the LICENSE file for more info.
Related Skills
qqbot-channel
351.4kQQ ้ข้็ฎก็ๆ่ฝใๆฅ่ฏข้ข้ๅ่กจใๅญ้ข้ใๆๅใๅๅธใๅ ฌๅใๆฅ็จ็ญๆไฝใไฝฟ็จ qqbot_channel_api ๅทฅๅ ทไปฃ็ QQ ๅผๆพๅนณๅฐ HTTP ๆฅๅฃ๏ผ่ชๅจๅค็ Token ้ดๆใๅฝ็จๆท้่ฆๆฅ็้ข้ใ็ฎก็ๅญ้ข้ใๆฅ่ฏขๆๅใๅๅธๅธๅญ/ๅ ฌๅ/ๆฅ็จๆถไฝฟ็จใ
docs-writer
100.6k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
351.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
arscontexta
3.1kClaude Code plugin that generates individualized knowledge systems from conversation. You describe how you think and work, have a conversation and get a complete second brain as markdown files you own.
