Skip to content

πŸ™Œ Video Trim, Crop, Rotate, Mute πŸ‘

License

Notifications You must be signed in to change notification settings

ohyeh/VideoConverter

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VideoConverter

CI Status Version License Platform Swift 5.0

Introduce

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.


VideoConverter

- - -
Trim Crop Rotate

Requirements

Installation

VideoConverter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'VideoConverter'

Usage

import VideoConverter
let videoConverter = VideoConverter(asset: asset)
videoConverter.convert { (url, error) in
    
}

convert

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)
    }
})

ConverterOption

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

ConverterCrop

var frame: CGRect // Crop position, size
var contrastSize: CGSize // Crop reference size

Author

pikachu987, [email protected]

License

VideoConverter is available under the MIT license. See the LICENSE file for more info.

About

πŸ™Œ Video Trim, Crop, Rotate, Mute πŸ‘

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.8%
  • Ruby 2.2%