• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

swif版微信视屏裁剪,类似微信朋友圈视频裁剪方式的视频裁剪工具(video croping)

🎉🚀📅🌎👍🎉

史上首款跟微信朋友圈视频裁剪相似的视频裁剪开源工具

Version License Platform Language

FGVideoEditor

  • 视频时长裁剪处理
  • 视频裁剪UI
  • 视频裁剪预览

Feathures

GIF演示

观看视频演示 Vedio

使用 Usage

微信样式视频裁剪只需要简单的使用(Simply use follow interface to crop a video in WeChat-style-lkie)

public convenience init(maxDuration:CGFloat, vedio url:URL, finishHandler:((FGVideoPreViewController, FGVideoInfo) -> ())?)

或者只裁剪不要UI(or just using crop function)

public func cropVideo(url: URL, cropRange:CMTimeRange, completion:((_ newUrl: URL, _ newDuration:CGFloat,_ result:Bool) -> ())?)

或者只用微信样式的视频裁剪UI(or just WeChat-style video croping UI)

public convenience init(frame: CGRect, url:URL, imgw:CGFloat, maxduration:CGFloat)
var cropStart:CGFloat //获取当前裁剪区域的左边界对应的时间(相对于视频开始播放的位置为0s)
var cropDuration:CGFloat //获取当前裁剪区域对应的时长
var cropRange:CMTimeRange //当前裁剪区域的CMTime范围
var cropWidth:CGFloat //当前裁剪区域的宽度
var slidingBeginHandler:(() -> ())?  //开始滑动视频裁剪区域的左/右边界的回调
var slidingHandler:((FGSlideDirection) -> ())?  //滑动视频裁剪区域的左/右边界的回调
var slidingEndHandler:(() -> ())? //结束左/右边界的滑动
var contentDidScrollHandler:(() -> ())? //滑动视频帧图片横向列表的回调
var dragWillBeginHandler:(() -> ())?  //将要滑动视频帧图片横向列表的回调
var dragDidEndHandler:(() -> ())?  //结束滑动视频帧图片横向列表的回调

你可以使用shouldSaveCropedVideoToPhotoLibrary来控制裁剪视频后是否自动保存至相册,默认是true (save croped video to photo library. default is true, set false to disable auto save to photo library)

示例(Example)

需要先选取一个视频

let picker = UIImagePickerController.init()
picker.sourceType = .photoLibrary
picker.mediaTypes = [kUTTypeMovie as String]
picker.delegate = wkself
picker.allowsEditing = false
present(picker, animated: true, completion: nil)

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    guard let url = info[UIImagePickerControllerMediaURL] as? URL else {
        picker.dismiss(animated: true, completion: nil)
        showHUD(.error("获取不到资源"))
        return
    }
    crop(video: url)
    picker.dismiss(animated: true, completion: nil)
}

利用预览视图裁剪,内置最小最大时长判断(croping and ui)

private func crop(video url:URL) {
    weak var wkself = self
    let preview = FGVideoPreViewController.init(max: 10, vedio: url) { (edit, info) in
        wkself?.cropedUrl = info.url
        wkself?.navigationController?.popViewController(animated: true)
        wkself?.playCropedVideo()
    }
    navigationController?.pushViewController(preview, animated: true)
}

private func playCropedVideo() {
    guard let url = cropedUrl else {
        return
    }
    pickBtn.isHidden = true
    
    player = AVPlayer.init(url: url)
    previewLayer = AVPlayerLayer.init(player: player)
    previewLayer?.backgroundColor = UIColor.clear.cgColor
    previewLayer?.videoGravity = .resizeAspectFill
    previewLayer?.frame = view.bounds
    view.layer.insertSublayer(previewLayer!, at: 0)
    player?.play()
}

仅使用视频裁剪能力(croping only)

FGVideoEditor.shared.cropVideo(url: url, cropRange: range, completion: { (newUrl, newDuration, result) in
    guard result else {
        self.showHUD(.error("剪切失败"))
        return
    }
    print("裁剪成功,裁剪后的路径:\(newUrl),时长:%.1f",newDuration)
})

仅使用视频裁剪UI(ui only)

let editFrame = CGRect.init(x: 50, y: screenheight - 100, width: screenwidth - 100, height: 50)
slider = FGVideoEditSliderView.init(frame: editFrame, url: url, imgw: imgw, maxduration: 10)
view.addSubview(slider)
weak var wkself = self
slider.slidingBeginHandler = {
    wkself?.player?.pause()
    wkself?.playing = false
}
let tolerance = CMTimeMake(1, timesclae)
slider.slidingHandler = { (direction) in
    let range = (wkself ?? self).slider.cropRange
    wkself?.currentRange = range
    if direction == .left {
        wkself?.player?.seek(to: range.end)
    } else {
        wkself?.player?.seek(to: range.start,
                             toleranceBefore: tolerance,
                             toleranceAfter: tolerance)
        wkself?.player?.seek(to: range.start)
    }
}
slider.slidingEndHandler = {
    wkself?.player?.seek(to: (wkself ?? self).currentRange.start)
    wkself?.player?.play()
    wkself?.playing = true
}
slider.contentDidScrollHandler = {
    let range = (wkself ?? self).slider.cropRange
    wkself?.currentRange = range
    wkself?.player?.seek(to: range.start)
}
slider.dragWillBeginHandler = {
    wkself?.player?.pause()
    wkself?.playing = false
}
slider.dragDidEndHandler = {
    wkself?.player?.play()
    wkself?.playing = true
}

安装 Installation

pod repo update
pod "FGVideoEditor", "~>1.2.1"

import FGVideoEditor

****若手动安装,请添加依赖:"SnapKit", "FGHUD", `"pod "FGToolKit"

环境 Required

  • Xocde 9
  • Swift 4.x

万水千山总是情,给个star行不行 欢迎pull request,欢迎isuue!

More Repositories

1

FGDownloader

用于断点下载、任务队列、上传进度、下载进度
Objective-C
147
star
2

HotFix

一种轻量级的可以通过苹果审核的热修复方案,可以替代JSPatch的热修复方案。
Objective-C
122
star
3

Custom-Camera

这是一个用AVFoundation框架制作的一个自定义相机Demo,包含了基本的点击屏幕对焦,以及焦距调整放缩功能。
Objective-C
22
star
4

XGFDownloader

FGGDwonloader的Swift版本,主要用于断点下载,后台下载,大文件下载
Swift
18
star
5

AVFoundationPlayer

用AVFoundation的AVPlayer做的一个小视频播放器,包括左滑快退,右滑快进,上滑音量加,下滑音量减等基本功能。
Objective-C
14
star
6

PlaneWar

Swift和SpriteKit编写的经典小游戏飞机大战
Swift
12
star
7

FGGAnimation

push视图时添加酷炫的转场动画
Objective-C
12
star
8

FGGTextField

实时监测文本格式是否正确的酷炫提示文本框
Objective-C
9
star
9

GeekMadeBySwiftUI

简单干货集中营的SwiftUI版本。网络请求用的Moya/RxSwift,网络请求回来的数据通过SwiftUI展示,SwiftUI网格视图用的第三方实现的。学习完官网的SwiftUI tutorials后的第一个实践项目
Swift
8
star
10

FGDoodlingBoard

涂鸦板,支持撤销、重做、清除、播放路径动画等,类似QQ涂鸦板。
Swift
8
star
11

CollectionHeaderView_Swift

用swift写的collectionView的demo,包含显示头部视图和脚部视图的实现方法
Swift
7
star
12

FGGAutomaticScrollView

一个方法创建自动循环滚动视图
Objective-C
7
star
13

FlappyBird

Swift和SpriteKit写的经典小游戏像素鸟Falppy Bird
Swift
7
star
14

FGSwiftAutoScrollView

Swift
6
star
15

FGGReachability

基于Reachability封装的网络判断,很好用,可以判断2G,2.75G,3G,4G,Wi-Fi,及可用,不可用等状态
Objective-C
6
star
16

Geek

Geek干货集中营,iOS swift版客户端
Swift
6
star
17

FGWebImage

An extension build in Swift for UIImageView and A light-weight framework of async loading image like SDWebImage.
Swift
5
star
18

FGHUD

An friendly and simple Swift HUD
Swift
5
star
19

FGHeaderView

[Swfit 3.0]一个方法一行代码实现表视图缩放
Swift
5
star
20

FCPopMenu

友好简易、可高度定制的下拉菜单。
Objective-C
5
star
21

FGTableHeaderView

一个方法实现表头部视图缩放
Objective-C
4
star
22

XMPPDemo

用Swift写的XMPP聊天的小Demo,登录注册、发消息、发文件、收消息、重连、踢账号、加好友等基础功能
Swift
4
star
23

FGSwiftUIImage

SwiftUI显示网络图片(SwiftUI web image likes SDWebImage)
Swift
4
star
24

SocketConnectDemo

iOS原生的Socket连接,跟服务器建立Socket连接,收发数据的小Demo
Objective-C
4
star
25

CoreDataDemo

CoreData的增删改查、筛选、排序等功能
Objective-C
3
star
26

FGToolKit

Swift便利工具集
Swift
3
star
27

SlideToShowLeftMenu

UITableView的左滑自定义多菜单Demo,兼容iOS 7
Objective-C
3
star
28

FGGSwtich

能改变大小的UISwitch-.-
Objective-C
3
star
29

FGGProgressHUD

简单好看的加载指示器
Objective-C
3
star
30

FGNetwork

A light networking kit for iOS with GET ,POST,file upload and multi files uploading supported
Objective-C
2
star
31

FGNumberSetpper

简易的选择数量控件,可以加、减、输入数量
Objective-C
2
star
32

USAction

类似SpriteKit的SKAction,你可以在UIKit上使用USAction,用法同SpriteKit的SKAction
Objective-C
2
star
33

UINavigationController-SmartPush

UINavigationController push到下一界面时自动隐藏底部UITabbar,pop回来时自动显示底部UITabbar
Objective-C
2
star
34

FGGCircleProgessView

简洁美观的环形进度条
Objective-C
2
star
35

3D_Touch_Demo

3DTouch的简单使用Demo
Objective-C
2
star
36

LeftMenu

实现UITableView的原生左滑多菜单自定义
Objective-C
2
star
37

FGGProgressHUD_Swift

FGGProgressHUD的Swift版本,简单好看的加载指示器
Swift
2
star
38

FGGWaterProgressView

球形水位高度效果的进度条
Objective-C
1
star
39

MultiDeleteAndMove

UITableView同时实现多选删除和移动两种功能
Objective-C
1
star
40

Insfgg99x.github.io

blog
HTML
1
star
41

DropDemo

一个简单的樱花飘落效果Demo,用SpriteKit实现的
Swift
1
star
42

FGAddressBook

获取手机通讯,监听手机通讯录的改变,并获取这些改变等。
Objective-C
1
star