MediaToolSwift
适用于 iOS、macOS 和 tvOS 的高级媒体转换器
视频
专注于
- 多种视频和音频编解码器
- 无损
- HDR 内容
- alpha 通道
- 慢动作
- 元数据
- 硬件加速
- 进度和取消
转换 | 调整大小 | 裁剪 | 切片 | 旋转、翻转、镜像 | 图像处理* | 帧率 | 缩略图 | 信息 |
---|---|---|---|---|---|---|---|---|
支持的视频编解码器
- H.264
- H.265/HEVC
- ProRes
- JPEG
此外,还支持解码以下编解码器:H.263, MPEG-1, MPEG-2, MPEG-4 Part 2
支持的音乐编解码器
- AAC
- Opus
- FLAC
- 线性 PCM
- Apple Lossless
示例
// 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: .hd, // CGSize to aspect fit in
// 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
.imageProcessing { image, _, _ in
image.applyingFilter("CIGaussianBlur", parameters: [
"inputRadius": 7.5
])
}
]
),
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 .progress(let progress):
print("Progress: \(progress.fractionCompleted)")
case .completed(let url):
print("Done: \(url.path)")
case .failed(let error):
print("Error: \(error.localizedDescription)")
case .cancelled:
print("Cancelled")
}
})
// Cancel the compression
task.cancel()
更复杂的示例可以在 此处 目录中找到。
需求
- macOS 11.0+
- iOS 13.0+
- tvOS 13.0+
安装
Swift 包管理器
使用 Swift 包管理器安装库,请将以下代码添加到您的 Package.swift 文件中
dependencies: [
.package(url: "https://github.com/starkdmi/MediaToolSwift.git", .upToNextMajor(from: "1.0.7"))
]
CocoaPods
使用 CocoaPods 安装库,请将以下行添加到您的 Podfile 文件中
pod 'MediaToolSwift', :git => 'https://github.com/starkdmi/MediaToolSwift.git', :version => '1.0.7'
文档
Swift DocC 文档托管在 GitHub Pages
有关视频功能和操作的更多信息,请在此处查找。