MediaToolSwift
Advanced Swift library for media conversion and manipulation
Install / Use
/learn @starkdmi/MediaToolSwiftREADME
MediaToolSwift
Advanced media converter for Apple devices
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.2.0"))
]
CocoaPods
To install library with CocoaPods, add the following line to your Podfile file:
pod 'MediaToolSwift'
VideoTool
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 | Frame 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: .fit(.hd), // size to fit or fill
// 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 or access pixel buffers
.process(.image { image, _, _ in
image.applyingGaussianBlur(sigma: 7)
})
]
),
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 .completed(let info):
print("Done: \(info.url.path)")
case .failed(let error):
print("Error: \(error.localizedDescription)")
case .cancelled:
print("Cancelled")
}
})
// Observe progress
task.progress.observe(\.fractionCompleted) { progress, _ in
print("Progress", progress.fractionCompleted)
}
// Cancel compression
task.cancel()
Complex example can be found in this directory.
ImageTool
Image converter focused on:
- Popular image formats
- Animated image sequences
- HDR content
- Metadata
- Orientation
- Multiple Frameworks
Features | Convert | Resize | Crop | Rotate, Flip, Mirror | Image Processing | FPS | Info | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
Supported image formats:
- HEIF
- HEIF 10-bit
- HEIC
- HEICS (HEIFS) ✨
- PNG ✨
- GIF ✨
- JPEG
- TIFF
- BMP
- JPEG 2000
- OpenEXR
- ICO
Additionally decoding is supported for: WebP ✨, AVIF and others
✨ - support animated image sequences
Example:
let info = try ImageTool.convert(
source: URL(fileURLWithPath: "input.webp"),
destination: URL(fileURLWithPath: "output.png"),
settings: .init(
format: .png,
size: .fit(.fhd), // size to fit in
// size: .crop(options: .init(size: CGSize(width: 512, height: 512), aligment: .center)), // or cropping area
// quality, frame rate, background color, atd.
edit: [
.rotate(.clockwise), // rotate and crop
// .rotate(.angle(.pi/4), fill: .blur(kernel: 55)), // rotate extend blurred
// .rotate(.angle(.pi/4), fill: .color(alpha: 255, red: 255, green: 255, blue: 255)), // rotate extend with color
// flip, mirror, atd.
// modify image frame(s)
.imageProcessing { ciImage, cgImage, _, _ in
guard let ciImage = ciImage else { return (ciImage, cgImage) }
return (ciImage.applyingGaussianBlur(sigma: 7), nil)
}
]
)
)
AudioTool
Audio converter focused on:
- Multiple audio formats
- Lossless
- Metadata
- Hardware Acceleration
- Progress and cancellation
Features | Convert | Cut | Info | | :---: | :---: | :---: | | ✔️ | ⭐️ | ✔️ |
⭐️ - do not require re-encoding (lossless)
Supported audio formats:
- AAC
- Opus
- FLAC
- Linear PCM
- Apple Lossless
Supported audio file containers are
M4A,WAV,CAF,AIFF,AIFC,AMR
Example:
// Run audio conversion
let task = await AudioTool.convert(
source: URL(fileURLWithPath: "input.mp3"),
destination: URL(fileURLWithPath: "output.m4a"),
// Audio
fileType: .m4a,
settings: .init(
codec: .flac,
bitrate: .value(96_000)
// quality, sample rate, volume, atd.
),
edit: [
.cut(from: 2.5, to: 15.0), // cut, in seconds
],
// Metadata
skipSourceMetadata: false,
customMetadata: [],
copyExtendedFileMetadata: true,
// File options
overwrite: false,
deleteSourceFile: false,
// State notifier
callback: { state in
switch state {
case .started:
print("Started")
case .completed(let info):
print("Done: \(info.url.path)")
case .failed(let error):
print("Error: \(error.localizedDescription)")
case .cancelled:
print("Cancelled")
}
})
// Observe progress
task.progress.observe(\.fractionCompleted) { progress, _ in
print("Progress", progress.fractionCompleted)
}
// Cancel conversion
task.cancel()
Documentation
Swift DocC documentation is hosted on Github Pages
Use those links for more info on video, image and audio features and operations.
Flutter
MediaToolSwift is available in Flutter via media_tool_flutter plugin.
Media Tool
There is a standalone macOS application based on MediaToolSwift source, more info can be found at mediatool.pro
Related Skills
healthcheck
347.6kHost security hardening and risk-tolerance configuration for OpenClaw deployments
imsg
347.6kiMessage/SMS CLI for listing chats, history, and sending messages via Messages.app.
xurl
347.6kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
qqbot-channel
347.6kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
