ChangbaDevs / KTVVideoProcess
- пятница, 1 июня 2018 г. в 00:16:40
Objective-C
A High-Performance video effects processing framework.
KTVVideoProcess is a High-Performance video effects processing framework. It's base on OpenGL ES, support asynchronous and multithread processing.
To integrate KTVVideoProcess into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'KTVVideoProcess', '~> 1.0.0'
Run pod install
To integrate KTVVideoProcess into your Xcode project using Carthage, specify it in your Cartfile:
github "ChangbaDevs/KTVVideoProcess" ~> 1.0.0
Run carthage update
to build the framework and drag the built KTVVideoProcess.framework
into your Xcode project.
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) {
if ([filter isKindOfClass:[KTVVPRGBFilter class]]) {
weakSelf.RGBFilter = filter;
weakSelf.RGBFilter.enable = NO;
weakSelf.RGBFilter.red = 1.0;
weakSelf.RGBFilter.green = 0.6;
weakSelf.RGBFilter.blue = 1.0;
} else if ([filter isKindOfClass:[KTVVPExposureFilter class]]) {
weakSelf.exposureFilter = filter;
weakSelf.exposureFilter.enable = NO;
weakSelf.exposureFilter.exposure = 0.5;
} else if ([filter isKindOfClass:[KTVVPBrightnessFilter class]]) {
weakSelf.brightnessFilter = filter;
weakSelf.brightnessFilter.enable = NO;
weakSelf.brightnessFilter.brightness = 0.2;
} else if ([filter isKindOfClass:[KTVVPBlackAndWhiteFilter class]]) {
weakSelf.blackAndWhiteFilter = filter;
weakSelf.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];
KTVVideoProcess is released under the MIT license.