Hi,
You should be able to use the registered video sink handler to obtain an image reference for the frame, which you can then manipulate as needed. Here is an example where the image is attached as an overlay on the screen:
- (void) videoFrameWasCaptured:(nonnull CVImageBufferRef)imageBuffer framePresentationTime:(CMTime)framePresentationTime frameDuration:(CMTime)frameDuration {
// _shouldCaptureImage is a class variable that is enabled/disabled
// by a button press. You don't want this updated every frame, it would get a bit insane.
if(_shouldCaptureImage){
// get frame reference as ciimage
CIImage *frameImage = [[CIImage alloc] initWithCVImageBuffer:imageBuffer];
CIContext *temporaryContext = [CIContext contextWithOptions:nil];
// get the cgimageref to inevitably conver to uiimage.
CGImageRef videoImage = [temporaryContext
createCGImage:frameImage
fromRect:CGRectMake(0, 0,
CVPixelBufferGetWidth(imageBuffer),
CVPixelBufferGetHeight(imageBuffer))];
// get uiimage and set the overlay position (just for
UIImage *image = [[UIImage alloc] initWithCGImage:videoImage];
capView.frame = CGRectMake(50,10, 40, 40);
// modify image on main thread
dispatch_async(dispatch_get_main_queue(), ^{
capView.image = image;
// if uiimageview already exists, you should just update it
// vs add another subview like we are doing here.
[self.view addSubview:capView];
});
}
}
Michelle