KTVVideoProcess
KTVVideoProcess是一个高性能的视频效果处理框架。它基于OpenGL ES,支持异步和线程处理。
流程图
安装
使用CocoaPods进行安装
要使用CocoaPods将KTVVideoProcess集成到Xcode项目中,请将其在Podfile中指定
pod 'KTVVideoProcess', '~> 1.1.0'
运行pod install
使用Carthage进行安装
要使用Carthage将KTVVideoProcess集成到Xcode项目中,请在其Cartfile中指定
github "ChangbaDevs/KTVVideoProcess" ~> 1.1.0
运行carthage update
来构建框架,并将构建的KTVVideoProcess.framework
拖入Xcode项目。
使用
- 整个过程需要三个节点:源/管道/输出。
源
- 源的责任是输入数据,如摄像头或媒体文件。
- 您可以根据以下示例创建摄像头源:
self.captureSession = [[KTVVPCaptureSession alloc] init];
self.captureSession.pipeline = self.pipeline;
if (needAudio) {
self.captureSession.audioEnable = YES;
self.captureSession.audioOutput = frameWriter;
}
[self.captureSession start];
管道
- 管道是实际的处理者。它包含多个过滤器。
- 有两种管道:串行和并发。串行管道在一个单独的线程上运行,一次只能处理一个任务。并发包含多个串行管道,这意味着它可以同时处理多个任务。但使用并发管道时,输出帧的时间戳可能不是连续的。
- 您可以根据以下示例创建串行管道:
NSArray <Class> * filterClasses = @[[KTVVPRGBFilter class],
[KTVVPExposureFilter class],
[KTVVPBrightnessFilter class],
[KTVVPBlackAndWhiteFilter class],
[KTVVPTransformFilter class]];
self.pipeline = [[KTVVPSerialPipeline alloc] initWithContext:self.context filterClasses:filterClasses];
__weak typeof(self) weakSelf = self;
[self.pipeline setFilterConfigurationCallback:^(__kindof KTVVPFilter * filter, NSInteger index) {
__strong typeof(weakSelf) self = weakSelf;
if ([filter isKindOfClass:[KTVVPRGBFilter class]]) {
self.RGBFilter = filter;
self.RGBFilter.enable = NO;
self.RGBFilter.red = 0.8;
} else if ([filter isKindOfClass:[KTVVPExposureFilter class]]) {
self.exposureFilter = filter;
self.exposureFilter.enable = NO;
self.exposureFilter.exposure = 0.5;
} else if ([filter isKindOfClass:[KTVVPBrightnessFilter class]]) {
self.brightnessFilter = filter;
self.brightnessFilter.enable = NO;
self.brightnessFilter.brightness = 0.2;
} else if ([filter isKindOfClass:[KTVVPBlackAndWhiteFilter class]]) {
self.blackAndWhiteFilter = filter;
self.blackAndWhiteFilter.enable = NO;
}
}];
[self.pipeline setupIfNeeded];
输出
- 它用于接收管道的结果。
- 您可以根据以下示例创建预览视图或文件写入器:
// Preview View
self.frameView = [[KTVVPFrameView alloc] initWithContext:self.context];
self.frameView.frame = self.view.bounds;
[self.view addSubview:self.frameView];
[self.pipeline addOutput:self.frameView];
// File Writer
NSString * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"KTVVideoProcess-temp.mov"];
self.frameWriter = [[KTVVPFrameWriter alloc] init];
self.frameWriter.outputFileURL = [NSURL fileURLWithPath:filePath];
self.frameWriter.videoOutputSize = KTVVPSizeMake(720, 1280);
self.frameWriter.videoEncodeDelayInterval = 0.0f;
if (needAudio) {
self.frameWriter.audioEnable = YES;
}
[self.frameWriter setStartCallback:^(BOOL success) {
NSLog(@"Record Started...");
}];
[self.frameWriter setFinishedCallback:^(BOOL success) {
NSLog(@"Record Finished...");
}];
[self.frameWriter setCancelCallback:^(BOOL success) {
NSLog(@"Record Canceled...");
}];
[self.frameWriter start];
if (needAudio) {
self.captureSession.audioOutput = self.frameWriter;
}
[self.pipeline addOutput:self.frameWriter];
导出
- 它用于处理现有视频。
- 您可以根据以下示例创建导出会话:
KTVVPExportSession * exportSession = [[KTVVPExportSession alloc] init];
exportSession.sourceURL = inputURL;
exportSession.destinationURL = outputURL;
exportSession.pipeline = pipeline;
[exportSession setCompletionCallback:^(NSURL * destinationURL, NSError * error) {
NSLog(@"KTVVPExportSession Finished");
}];
[exportSession start];
后台模式
- 您需要做一些事情来避免后台进程运行
// Suspend the Source/Pieple/Output
self.captureSession.paused = YES;
[self.pipeline glFinish];
[self.frameWriter cancel];
// Wait until all operations are finished.
[self.pipeline waitUntilFinished];
[self.frameView waitUntilFinished];
[self.frameWriter waitUntilFinished];
转换
- 如果视频帧包含变换(旋转/翻转/...),但输出无法处理变换。您可以在Pipeline末尾添加一个KTVVPTransformFilter。如果需要,它将处理变换。
许可
KTVVideoProcess遵循MIT许可证发布。
反馈
- GitHub : Single
- Email : [email protected]
- Twitter : CoderSingle
- 微博 : 程序员Single
由Single开发
- SGPlayer - 一个强大的iOS、macOS和tvOS媒体播放器框架。
- KTVHTTPCache - 一个智能媒体缓存框架。