To run the example project, clone the repo and run pod install
from the Example directory first.
- iOS 9.0+
- Swift 5.0+
ShortClipVideoTrimmerUI is available through CocoaPods. To install it, simply add the following line to your Podfile
:
pod 'ShortClipVideoTrimmerUI'
Then run:
pod install
⚠️ Note
This library only provides the UI for video trimming with frames.
It does not perform the actual trimming.
You will receive the trimming area's start and end times, and can handle trimming based on that.
Create an instance of ShortClipVideoTrimmerContentView
(via Interface Builder or code) and add it to your view hierarchy:
shortClipTrimmerContentView.delegate = self
shortClipTrimmerContentView.startOperation(
asset: asset,
maxTrimmingDuration: maxTrimmingDuration,
numberOfFramesPerCycle: numberOfFramesPerCycle
)
asset
is anAVAsset
object.maxTrimmingDuration
defines the maximum trimming length.numberOfFramesPerCycle
controls how many frames are shown in one cycle.
Sync the trimmer’s position bar with video playback:
// videoPlayer is an instance of AVPlayer
videoPlayer.addPeriodicTimeObserver(
forInterval: CMTime(seconds: 0.01, preferredTimescale: 600),
queue: .main
) { _ in
shortClipTrimmerContentView.updatePositionBarConstraint(cmTime: videoPlayer.currentTime())
}
You can customize the appearance of ShortClipVideoTrimmerContentView
:
shortClipTrimmerContentView.updateHandlerWidth(width: 10.0)
shortClipTrimmerContentView.updateKnobWidth(width: 3.0)
shortClipTrimmerContentView.updatePositionBarWidth(width: 4.0)
shortClipTrimmerContentView.updateTrimmingAreaBorderWidth(width: 2.0)
shortClipTrimmerContentView.handlerColor(color: .blue)
shortClipTrimmerContentView.updateTrimmingAreaBorderColor(color: .blue)
shortClipTrimmerContentView.updateKnobColor(color: .white)
shortClipTrimmerContentView.updatePositionBarColor(color: .white)
shortClipTrimmerContentView.updateTrimmingOutsideBackgroundColor(color: .white)
shortClipTrimmerContentView.updateTrimmingOutsideMaskAlpha(alpha: 0.5)
By conforming to the ShortClipVideoTrimmerContentViewDelegate
, you can receive updates when the trimming start or end positions change.
For more information, check the example project.
Sagar Chandra Das
Email: [email protected]
ShortClipVideoTrimmerUI is available under the MIT License.