A set of tools to trim, crop and select frames inside a video

Overview

PryntTrimmerView

codebeat badge Platform License Version Carthage compatible Swift Package Manager

A set of tools written in swift to crop and trim videos.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Trimming

Cropping

Requirements

PryntTrimmerView requires iOS9: It uses Layout Anchors to define the constraints.

Installation

SPM

Add the following to your Package.swift file

dependencies: [
    .package(url: "https://github.com/HHK1/PryntTrimmerView.git", .upToNextMajor(from: "4.0.1"))
]

CocoaPods

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

pod "PryntTrimmerView"

Then, run pod install to download the source and add it to your workspace.

Carthage

PryntTrimmmerView is available through Carthage. To install it, simply add the following line to your Cartfile:

github "HHK1/PryntTrimmerView"

Run carthage update to build the framework and drag the built PryntTrimmerView.framework into your Xcode project.

Swift Version

  • Swift 3 compatibility: use version 1.0.1 or below.
  • Swift 4 compatibility: use version 2.x.x.
  • Swift 4.2 compatibility: use version 3.x.x

Usage

⚠️ This library does not contain an API to crop or trim your video asset. You can find a possible implementation for this in the example pod, but the library only provides the UI.

Trimming

Create a TrimmerView instance (in interface builder or through code), and add it to your view hierarchy.

trimmerView.asset = asset
trimmerView.delegate = self

Access the startTime and endTime property to know where to trim your asset. You can use the TrimmerViewDelegate to link the trimmer with an AVPlayer and provide the end user with a preview. See the VideoTrimmerViewController inside the project to see an example.

You can also customize the trimmer view by changing its colors:

trimmerView.handleColor = UIColor.white
trimmerView.mainColor = UIColor.orange
trimmerView.positionBarColor = UIColor.white

Cropping

Create an instance of the VideoCropView and add it to your view hierarchy, then load your video into the crop view: videoCropView.asset = asset.

You can set the aspect ratio you want using the setAspectRatio method. Once you are satisfied with the portion of the asset you want to crop, call getImageCropFrame to retrieve the select frame. See the VideoCropperViewController in the example app for an actual example of how to crop the video for export.

License

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

Comments
  • New Pod version for swift 4.2

    New Pod version for swift 4.2

    Hi @HHK1

    We are encountering an issue with Swift 4.2 on our picker. https://github.com/Yummypets/YPImagePicker/issues/224

    After some research, it looks like we'd need to have a pod version uploaded for PryntTrimmerView in swift 4.2.

    Trying to link the dependency from the tag3.0.0-beta.1 doesn't work for some reason unfortunately :/

    [!] Invalid `YPImagePicker.podspec` file: [!] Unsupported version requirements.
    
     #  from /Users/sacha/Projects/YPImagePicker/YPImagePicker.podspec:16
     #  -------------------------------------------
     #    s.dependency 'SteviaLayout', '~> 4.4.0'
     >    s.dependency 'PryntTrimmerView', :git => 'https://github.com/HHK1/PryntTrimmerView.git', :tag => '3.0.0-beta.1'
     #    s.resources    = ['Resources/*', 'Source/**/*.xib']
     #  -------------------------------------------
    

    I think you'd need to push a new version for instance 2.1.0 based on 3.0.0-beta.1 code then pod trunk push.

    Thanks a ton for your help :)

    opened by s4cha 24
  • Crash in regenerateThumbnails(for asset: AVAsset)

    Crash in regenerateThumbnails(for asset: AVAsset)

    let visibleThumbnailsCount = Int(ceil(frame.width / thumbnailSize.width)) line gives a crash

    2018-04-18 21 15 55

    Before this the AVAssetTimeSelector.frame gives (30.0, 88.0, 315.0, 56.0), but assetPreview.frame gives (0.0, 0.0, 0.0, 0.0). I think the problem is with frames.

    opened by NikKovIos 11
  • Great tool <3

    Great tool <3

    Hey @HHK1, great tool you have here !

    This is a feature that was requested in our media picker and some users pointed us towards you library. Just wanted to let you know that we are looking at integrating PryntTrimmerView as a dependency as part of our Media Picker tool YPImagePicker.

    Begining implementation can be found: here

    Let me know how you'd feel about that :)

    Cheers!

    opened by s4cha 10
  • Update pod spec version

    Update pod spec version

    Hello @HHK1,

    I just adjusted the pod spec can you upload it to COCOAPODS, please?

    And I added to changelog the fix of CSTime to NSValue casting, because is a brake change on XCode 12 and will be easier to see this if someone using an old version of your lib.

    Thank you so much.

    Douglas

    opened by mendesbarreto 8
  • Could not calculate the thumbnail size.

    Could not calculate the thumbnail size.

    Hello There,

    I'm trying to load thumbnails from my video into trim view. But I have the following error: Could not calculate the thumbnail size.

    This is my video's location: file:///private/var/mobile/Containers/Data/PluginKitPlugin/D7ABED4E-C54A-4948-B7D3-5587AE62358D/tmp/trim.CCA9A520-F11E-4BA6-A3A8-B15AA9E05CAC.MOV

    IMG_9415

    What could be happening?

    Best Regards

    opened by alfredolucomav 7
  • Change type casting CMTime to NSValue using NSValue constructor

    Change type casting CMTime to NSValue using NSValue constructor

    What is this PR for?

    Change type cast CMTime to NSValue using NSValue constructor

    Why are we doing this?

    XCode 12.0 beta 6, iOS 14, Swift 5 Fix Compile error "Cannot convert value of type 'CMTime' to type 'NSValue in coercion"

    ScreenShots

    스크린샷 2020-08-29 오후 5 03 41 스크린샷 2020-08-29 오후 6 06 03
    opened by heoblitz 6
  • How to create a trimmer View in a new UIViewController.

    How to create a trimmer View in a new UIViewController.

    screen shot 2017-10-17 at 7 07 32 pm screen shot 2017-10-17 at 7 09 58 pm

    I want to create a trimmer View in a new view controller. I created a new view controller in the sample project and one view and a trimmerView in viewController. I have few doubt in this.

    1. In storyboard while assigning the class to the view(brown view) Class name is display as trimmerView but while creating outlets in file trimmerView is not displaying. it is displaying as PryntTrimmerView and connection is not applicable to that view.

    2. I tried to create dynamically but the properties trimmerView.asset = asset trimmerView.delegate = self trimmerView.handleColor = UIColor.white trimmerView.mainColor = UIColor.orange trimmerView.positionBarColor = UIColor.white

    are not calling and not displaying in view controller. Please give suggestion to implement the Trimmerview in UiViewController and can use the properties and delegate methods to trim the video.

    Thank you

    opened by ajay2c9 6
  • XCode 10 GM and Swift 4.2 fail to build

    XCode 10 GM and Swift 4.2 fail to build

    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/Cropper/CropMaskView.swift:33:30: 'kCAFillRuleEvenOdd' has been renamed to 'CAShapeLayerFillRule.evenOdd'
    /Users/joelaws/Workspace/kratos/Pods/QuartzCore.kCAFillRuleEvenOdd:3:12: 'kCAFillRuleEvenOdd' was obsoleted in Swift 3
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/Cropper/CropMaskView.swift:108:64: 'kCAMediaTimingFunctionEaseInEaseOut' has been renamed to 'CAMediaTimingFunctionName.easeInEaseOut'
    /Users/joelaws/Workspace/kratos/Pods/QuartzCore.kCAMediaTimingFunctionEaseInEaseOut:3:12: 'kCAMediaTimingFunctionEaseInEaseOut' was obsoleted in Swift 3
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/Cropper/CropMaskView.swift:109:30: 'kCAFillModeBoth' has been renamed to 'CAMediaTimingFillMode.both'
    /Users/joelaws/Workspace/kratos/Pods/QuartzCore.kCAFillModeBoth:3:12: 'kCAFillModeBoth' was obsoleted in Swift 3
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/ThumbSelectorView.swift:122:50: 'kCMTimeZero' has been renamed to 'CMTime.zero'
    /Users/joelaws/Workspace/kratos/Pods/CoreMedia.kCMTimeZero:3:12: 'kCMTimeZero' was obsoleted in Swift 4.2
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/ThumbSelectorView.swift:123:51: 'kCMTimeZero' has been renamed to 'CMTime.zero'
    /Users/joelaws/Workspace/kratos/Pods/CoreMedia.kCMTimeZero:3:12: 'kCMTimeZero' was obsoleted in Swift 4.2
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/Parents/AssetVideoScrollView.swift:139:65: 'AVAssetImageGeneratorResult' has been renamed to 'AVAssetImageGenerator.Result'
    /Users/joelaws/Workspace/kratos/Pods/AVFoundation.AVAssetImageGeneratorResult:2:18: 'AVAssetImageGeneratorResult' was obsoleted in Swift 4.2
    /Users/joelaws/Workspace/kratos/Pods/PryntTrimmerView/PryntTrimmerView/Classes/Parents/AssetVideoScrollView.swift:162:78: 'UIImageOrientation' has been renamed to 'UIImage.Orientation'
    /Users/joelaws/Workspace/kratos/Pods/UIKit.UIImageOrientation:2:18: 'UIImageOrientation' was obsoleted in Swift 4.2
    
    opened by jlaws 4
  • Swift 4.1 Cannot override with a stored property '...Constraint'

    Swift 4.1 Cannot override with a stored property '...Constraint'

    class AssetVideoScrollView: UIScrollView {
        private var widthConstraint: NSLayoutConstraint?
    

    and the same error with

      @IBDesignable public class TrimmerView: AVAssetTimeSelector {
        private var leftConstraint: NSLayoutConstraint?
        private var rightConstraint: NSLayoutConstraint?
    

    You can check it in https://github.com/Yummypets/YPImagePicker/commit/4fea39d9c3688a1ea8e36ae83dcce59a507c3e3d

    opened by NikKovIos 4
  • Swift 5 Support w/ Cocoapods

    Swift 5 Support w/ Cocoapods

    Expected Results

    No warning to convert PryntTrimmerView.framework to Swift 5

    Actual Results

    Xcode created warnings to convert PryntTrimmerView.framework to Swift 5

    Steps to Reproduce

    Build the cocoapod in Xcode 10.2

    opened by jlaws 3
  • Open up parent classes so that they can be extended outside this project

    Open up parent classes so that they can be extended outside this project

    Hi,

    I'd like to extend or use AVAssetTimeSelector and AssetVideoScrollView outside this project, basically use them to write something similar to TrimmerView. Right now I couldn't do this because the classes are not open, and some properties are internal (such as assetPreview).

    Thanks

    opened by jraoatlogic 3
  • Render Size question [question]

    Render Size question [question]

    Hi!

    Thanks for the awesome tool

    I was reading a code related to the video cropping. There is one thing I can't wrap my head around

    CGSize(width: 16 * videoCropView.aspectRatio.width * 18,
                                    height: 16 * videoCropView.aspectRatio.height * 18)
    

    Could you please explain why we need to multiple aspectRatio by 16 and 18 ?

    and why scale is determined by dividing width on width let renderScale = renderSize.width / cropFrame.width

    Thanks!

    opened by romaHerman 2
  • Fixed compiler warning about invalid file excludes in Package.swift

    Fixed compiler warning about invalid file excludes in Package.swift

    In this PR I updated the exclude section of the Package.swift to correctly point to the license file and the example project.

    Background: as a "home" directory the SPM uses <package_folder>/Sources/<package_name_folder> path format, so in our case this is: PryntTrimmerView/Sources/PryntTrimmerView/. Therefore SPM tries to find the license and example project over there, however, these items are located two levels up in fact — in the package root.

    #83

    opened by Edward-Bazko 0
  • [Warning, Xcode 13, SPM] Invalid Exclude files

    [Warning, Xcode 13, SPM] Invalid Exclude files

    New warnings appear after building project in Xcode 13 using SPM for installation.

    Invalid Exclude '.../SourcePackages/checkouts/PryntTrimmerView/Sources/PryntTrimmerView/PryntTrimmerViewExample': File not found.
    
    Invalid Exclude '.../SourcePackages/checkouts/PryntTrimmerView/Sources/PryntTrimmerView/LICENSE': File not found.
    

    I guess it can be removed from the exclude section in Package.swift?

    opened by SonnyMore 1
  • Frames issue

    Frames issue

    Hi! When I display the asset inside the trimmerView, on the simulator all frames appear. But when I try working on a real device, only the first frame appears I am using: xCode 12.4, iOS 14.4.2

    opened by g-farah 0
Releases(4.0.2)
Owner
Henry Huck
Henry Huck
How to Display Video from URL inside custom design UIView

Technicalisto How to Display Video from URL inside custom design UIView Add your UIView and connect it . Add This method for display func DisplayVideo

Aya Baghdadi 1 Jun 24, 2022
Video mp4 record save display - How to Take , Save and Display a .mp4 Video

Technicalisto How to Take , Save and Display a .mp4 Video Add your design with v

Aya Baghdadi 2 Aug 7, 2022
A fully functional short video app project.Record a six secends video while playing prank sounds.

prankPro A fully functional short video app project How to Install 1. use coconapod to init your xcode environment. 2. change the app-keys in `applica

huijimuhe 258 Jun 19, 2022
JDVideoKit - You can easily transfer your video into Three common video type.

JDVideoKit Introduction You can easily transfer your video into Three common video type. You can use set up camera easily. Installation pod 'JDVideoK

郭介騵 24 Sep 9, 2021
A Swift library to upload video files to api.video platform.

api.video IOS video uploader api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and manag

api.video 7 Dec 9, 2022
api.video is the video infrastructure for product builders

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

api.video 4 Jun 27, 2022
A set of extensions and utilities to work with CoreVideo types.

core-video-tools A set of extensions and utilities to work with CoreVideo types. CVPixelFormat While debuging Core Video objects, you need to understa

eugene 6 Dec 30, 2022
High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

BearRuan 650 Dec 30, 2022
Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey

Video player with support for Invidious and Piped instances built for iOS 15, tvOS 15 and macOS Monterey.

Yattee 1k Dec 27, 2022
Yattee: video player for Invidious and Piped built for iOS, tvOS and macOS

Video player for Invidious and Piped instances built for iOS, tvOS and macOS. Features Native user interface built with SwiftUI Multiple instances and

Yattee 1.1k Jan 8, 2023
A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.

A high-level video composition framework build on top of AVFoundation. It's simple to use and easy to extend. Use it and make life easier if you are implementing video composition feature.

VideoFlint 1.4k Dec 25, 2022
▶️ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Jan 2, 2023
Repository with base samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Includes steps for encoding and packaging your own test content.

Video Everything Repository with minimal samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Content and License All t

Alex Dodge 3 Jul 4, 2021
📽 A video player for SwiftUI, support for caching, preload and custom control view.

Features QuickStart Advances Installation Requirements License Demo Clone or download the project. In the terminal, run swift package resolve. Open Vi

Gesen 437 Jan 5, 2023
Swift Package used for video where I demonstrate how to extract a package to a local framework and modify it.

SegmentedPicker NOTE: This sample code is taken from the article by Frank Jia in his article titled Build a Custom iOS Segmented Control With SwiftUI

Stewart Lynch 1 Oct 11, 2021
iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

Abe Wang 11 Nov 7, 2022
YouTube video player for iOS, tvOS and macOS

About XCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS. Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also a

Cédric Luthi 2.9k Jan 7, 2023
A Photo and Video Gallery

================== bitcoin:1Lj45X69tPYAPqnZP2c9Ccs349fC2CEMQo Podfile platform :ios, '7.0' pod 'MHVideoPhotoGallery' Supported Videos Youtube Vimeo We

Mario Hahn 2k Jan 4, 2023
Paging Video UI, and some control components is available.

VideoPager [![CI Status](http://img.shields.io/travis/Takuya Okamoto/VideoPager.svg?style=flat)](https://travis-ci.org/Takuya Okamoto/VideoPager) Demo

Takuya Okamoto 55 Dec 23, 2022