2

I'm working on an app which use GPUImage framework. I want to use GPUImageWhiteBalanceFilter to adjust whitebalance and record some watermark use uiElement blend, it works but the framerate is poor when capture 1080p video in iphone 4s. Codes as follows and could anyone pls give a help.

if (filter==nil) {
    filter = [[GPUImageWhiteBalanceFilter alloc] init];
}
[((GPUImageWhiteBalanceFilter *)filter) setTemperature:3000];
[videoCamera addTarget:filter];
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 0.8;

NSDate *startTime = [NSDate date];

UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 240.0f, 320.0f)];
timeLabel.font = [UIFont systemFontOfSize:17.0f];
timeLabel.text = @"Time: 0.0 s";
timeLabel.textAlignment = UITextAlignmentCenter;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];

uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel];

[filter addTarget:blendFilter];
[uiElementInput addTarget:blendFilter];

[blendFilter addTarget:filterView];

__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;

[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){

    timeLabel.text = [NSString stringWithFormat:@"Time: %f s", -[startTime timeIntervalSinceNow]];
    [weakUIElementInput update];
}];


NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/CPMovie.mov"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoDimensions.width , videoDimensions.height)];
//[videoCamera addTarget:movieWriter];
//to record filtered video
[blendFilter addTarget:movieWriter];
[videoCamera startCameraCapture]; 
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
JonnyHan
  • 97
  • 4
  • Do you absolutely have to update the time display every frame? You're re-rendering text 30 times a second, which is going to be a slow operation. Maybe only do that a few times a second. – Brad Larson Sep 12 '12 at 14:49
  • Thanks, Brad. Actually, I do not quite understand the GPUImageUIElement class working flow. I think I must use setFrameProcessingCompletionBlock and [weakUIElementInput update], if not, I'll get a white screen in the preview. Do we have other methods to avoid so many re-rending operation? – JonnyHan Sep 13 '12 at 01:40
  • Only update the text in the label and call `-update` once every few times that processing block is called. There's no need to call it on every single frame. You could do that with a counter and an if() statement. – Brad Larson Sep 13 '12 at 02:13
  • It saves my ass. I missunderstanding the setFrameProcessingCompletionBlock method before. Thanks. – JonnyHan Sep 13 '12 at 03:26
  • I use this code: __block int framecount=0; and framecount++; if (framecount==30) {} I can only get about 22fps@1080p on iPhone 4s, is there any availability to improve the fps? – JonnyHan Sep 13 '12 at 04:24
  • Using the Time Profiler instrument, where are the bottlenecks here? Are they in the movie encoding, interface update, or filtering? – Brad Larson Sep 13 '12 at 17:46
  • Movie writer with filter cost the most time. – JonnyHan Sep 14 '12 at 09:08

0 Answers0