我目前正在使用 GPU框架来录制视频以及 WhiteBalance和曝光过滤器,但FPS非常差(约12 FPS)。我在GPUImage原始演示代码( SimpleVideoFilter )中使用了上述过滤器,但结果相同。
以下是我用来录制带有组合滤镜的视频的方法。这些是iPhone 5,iPod Touch的结果,支持最多30 FPS。
任何想法 FPS高达28 或 AVCaptureSessionPresetHigh 和WhiteBalance,Exposure过滤器一起!!谢谢!!
-(void)recordVideo{
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = NO;
filter = [[GPUImageFilterGroup alloc] init];
[videoCamera addTarget:filter];
GPUImageFilterGroup *group = (GPUImageFilterGroup *)filter;
GPUImageWhiteBalanceFilter *whiteBalance = [[GPUImageWhiteBalanceFilter alloc] init];
[group addFilter:whiteBalance];
GPUImageExposureFilter *exposureFilter = [[GPUImageExposureFilter alloc] init];
[group addFilter:exposureFilter];
[whiteBalance addTarget:exposureFilter];
[group setInitialFilters:[NSArray arrayWithObject:whiteBalance]];
[group setTerminalFilter:exposureFilter];
filter = group;
[videoCamera addTarget:filter];
GPUImageView *filterView = (GPUImageView *)self.view;
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter.encodingLiveVideo = YES;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1080.0, 1920.0)];
[filter addTarget:movieWriter];
[filter addTarget:filterView];
[videoCamera startCameraCapture];
double delayToStartRecording = 0.5;
dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Start recording");
videoCamera.audioEncodingTarget = movieWriter;
[movieWriter startRecording];
double delayInSeconds = 10.0;
dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){
[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
NSLog(@"Movie completed");
});
});
}