Video can be cropped by x, y, width, and height, and can be rotated 0, 90, 180, 270 degrees. And you can adjust the duration of video playback with startTime and endTime or durationTime, and you can also mute mode.
- | - | - |
---|---|---|
Trim | Crop | Rotate |
---|---|---|
VideoConverter is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'VideoConverter'
import VideoConverter
let videoConverter = VideoConverter(asset: asset)
videoConverter.convert { (url, error) in
}
videoConverter.convert(<#T##option: ConverterOption?##ConverterOption?#>, progress: <#T##((Double?) -> Void)?##((Double?) -> Void)?##(Double?) -> Void#>, completion: <#T##((URL?, Error?) -> Void)##((URL?, Error?) -> Void)##(URL?, Error?) -> Void#>)
var videoConverterCrop: ConverterCrop?
if let dimFrame = self.videoView.dimFrame {
videoConverterCrop = ConverterCrop(frame: dimFrame, contrastSize: self.videoView.videoRect.size)
}
videoConverter.convert(ConverterOption(
trimRange: CMTimeRange(start: self.videoTrim.startTime, duration: self.videoTrim.durationTime),
convertCrop: videoConverterCrop,
rotate: CGFloat(.pi/2 * self.rotate),
quality: self.preset,
isMute: self.isMute), progress: { [weak self] (progress) in
self?.progressView.setProgress(Float(progress ?? 0), animated: false)
}, completion: { [weak self] (url, error) in
if let error = error {
let alertController = UIAlertController(title: nil, message: error.localizedDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Confirm", style: .default, handler: nil))
self?.present(alertController, animated: true)
} else {
self?.convertVideoView.url = url
self?.progressView.setProgress(0, animated: false)
}
})
var trimRange: CMTimeRange // Start time and end time or start time and duration time
var convertCrop: ConverterCrop // Crop position, size
var rotate: CGFloat // radian rotation
var quality: String // Video quality
var isMute: Bool // Mute mode
var frame: CGRect // Crop position, size
var contrastSize: CGSize // Crop reference size
pikachu987, [email protected]
VideoConverter is available under the MIT license. See the LICENSE file for more info.