Brad Larson によるGPUImage クラスを使用できます。要件に応じて、画像とビデオにフィルターを追加できます。最近、私のプロジェクトの 1 つで、あなたが求めていたものとまったく同じものを実装しました。
私がしたことは、UILabel を as として使用しGPUImageUIElement
、それを に追加することでしたGPUImageNormalBlendFilter
。コールバックごとにラベル テキストを更新したところ、魅力的に機能しました。
コードは次のとおりです。
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];
}];
私は質問が古いことを知っていますが、これを見つけるのに時間がかかったので誰かを助けるかもしれません.