Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text overlay not showing in GPUImage iOS

I am trying to overlay some text on a video and have not had any success so far.

videoCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0, 1, 1)];
mCurrentImage = [UIImage imageNamed:@"tex16"];
sourcePicture = [[GPUImagePicture alloc] initWithImage:mCurrentImage smoothlyScaleOutput:NO];
[sourcePicture processImage];

customFilter = [[GPUFilter alloc] initWithFragmentShaderFromFile:@"shader"];
[videoCamera addTarget:cropFilter];
[cropFilter addTarget:customFilter atTextureLocation:0];
[sourcePicture addTarget:customFilter atTextureLocation:1];
[customFilter addTarget:mViewCameraPreview];//(GPUImageView*)mViewCameraPreview];

blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
blendFilter.mix = 1.0;

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 = NSTextAlignmentCenter;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];

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

[customFilter addTarget:blendFilter];
[uiElementInput addTarget:blendFilter];
[blendFilter addTarget:mViewCameraPreview];

[videoCamera startCameraCapture];

Everything complies and runs without throwing any exceptions, however there is no text to be found.

Does anyone see what I am doing wrong?

Thanks.

like image 717
Clip Avatar asked Dec 09 '25 05:12

Clip


1 Answers

Did you try performing an update of UIElementInput right after starting camera capture ? If not, please try to add this code at the end of the code you provided.

__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
    [weakUIElementInput update];
}];

If it doesn't work or if you've already did it, you should try with a basic filter (no custom filter) to see if the problem persists.

like image 54
AnthoPak Avatar answered Dec 10 '25 18:12

AnthoPak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!