You can use the GPUImage class from Brad Larson, it allows you to add a filter to the image and video according to your requirement. I just implement what you asked for in one of my projects recently.
I used UILabel as a GPUImageUIElement and added it to the GPUImageNormalBlendFilter . I updated the label text with every callback and it worked like a charm.
Here is the code:
filterView = [[GPUImageView alloc] initWithFrame:self.videoRecordView.frame]; videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920,1080)]; [self.view addSubview:filterView]; movieWriter.encodingLiveVideo = YES; movieWriter.encodingLiveVideo = YES; videoCamera.audioEncodingTarget = movieWriter; GPUImageNormalBlendFilter *blendFilter1 = [[GPUImageNormalBlendFilter alloc] init]; UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 635, 768.0f, 50.0f)]; timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; timeLabel.textAlignment = NSTextAlignmentCenter; timeLabel.backgroundColor = [UIColor clearColor]; timeLabel.textColor = [UIColor whiteColor]; uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel]; [uiElementInput addTarget:blendFilter1]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"MMMM dd, yyyy hh : mm : ss a"]; [blendFilter1 addTarget:filterView]; [blendFilter1 addTarget:movieWriter]; [videoCamera addTarget:blendFilter1]; __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){ timeLabel.textColor =[UIColor whiteColor]; float sizefont =[[[NSUserDefaults standardUserDefaults]objectForKey:KfontSize] floatValue]; timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(sizefont)? sizefont:30]; NSDate * originalDate = [NSDate dateWithTimeIntervalSinceNow:interval]; NSString *timeString=[dateFormatter stringFromDate:originalDate]; timeLabel.text = [NSString stringWithFormat:@"%@", timeString]; [weakUIElementInput update]; }];
I know the question is old, but it might help someone, since it took me a while to find this.
Bhumit mehta
source share