YGCTrimVideoView
微信类似的视频剪辑时间视图。
特性
- 左右时间控制
- 自定义左右侧边栏
- 支持设置最大和最小时长
- 从您的时间裁剪设置中导出视频文件
外观
使用方法
初始化
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName"
ofType:@"MP4"];
YGCTrimVideoView *ygcTrimView = [[YGCTrimVideoView alloc] initWithFrame:CGRectMake(0, 75, self.view.bounds.size.width, 80)
assetUR:[NSURL fileURLWithPath:path]];
[self.view addSubview:self.ygcTrimView];
就这样了
自定义界面
- (id)initWithFrame:(CGRect)frame
leftControlImage:(UIImage *)leftImage
rightControlImage:(UIImage *)rightImage
centerRangeImage:(UIImage *)centerImage
sideBarWidth:(CGFloat)sidebarWidth;
leftImage
你可以设置左侧边栏使用图片rightImage
与leftImage
相同centerRangeImage
滑块的周围边框图片,可能需要设置图片的调整插入sideBarWidth
控制条宽度
设置最大和最小时长
只需设置属性 maxSeconds
和 minSeconds
。
// min duration is 2 and max duration is 10
self.ygcTrimView.minSeconds = 2;
self.ygcTrimView.maxSeconds = 10;
预览裁剪视频
在委托函数中
- (void)dragActionEnded:(AVMutableComposition *)asset
每次你完成控制条拖动后,YGCTrimView 会生成一个 AVMutableComposition。你可以创建 AVPlayer 并直接播放该组合。例如
- (void)dragActionEnded:(AVMutableComposition *)asset {
self.playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
[self.player replaceCurrentItemWithPlayerItem:self.playerItem];
[self.player play];
}
导出视频
YGCTrimVideoView 支持两种导出视频文件的方式。
第一种方法
- (void)dragActionEnded:(AVMutableComposition *)asset;
从委托函数中获取 AVMutableComposition。AVMutableComposition 是 AVAsset。因此,您可以使用 AVExportSession 从 AVMutableComposition 导出视频文件。
第二种方法
- (void)exportVideo:(YGCExportFinished)finishedBlock;
您可以直接使用函数来导出视频文件。The finishedBlock 将为您从沙盒中提供视频 URL。
安装
Cocoapods
在你的 podfile 中。
pod 'YGCTrimVideoView', '~> 0.2.3'
然后如果遇到错误“无法满足以下要求”,请使用
pod install --repo-update
需求
- iOS 10 或更高版本
作者
- 张奇龙 - zangqilong
交流
- 如果你 发现了 bug,请提交一个问题。
- 如果你 有功能请求,请提交一个问题。
- 如果你想 贡献,请提交一个拉取请求。
许可证
本项目遵循 MIT 许可证。