Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureVideoPreviewLayer not working with renderInContext

I have an AVCaptureVideoPreviewLayer (that works fine showing the video fullscreen) that I am trying to show a small preview in another small view that I have added as a subview. To do this, I was trying to use renderInContext but all I get is a black screen in my "preview view".

[[self.captureView.layer.sublayers objectAtIndex:0] renderInContext:context];

Any other layers seem to work fine and show up in my "preview view", why does AVCaptureVideoPreviewLayer not?

like image 684
Nic Hubbard Avatar asked Apr 22 '12 18:04

Nic Hubbard


1 Answers

AVCaptureVideoPreviewLayer is implemented as an OpenGL layer, which does not implement renderInContext along with some other aspects of the CoreAnimation composition model, whatever that means.

Quoth Apple in the CALayer documentation of renderInContext:

Important The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values. Future versions of Mac OS X may add support for rendering these layers and properties.

As of iOS 5.1.1, this is still the case.

The way I dealt with was by using AVCaptureVideoDataOutput and sending the captured sample buffer into a handy code sample called imageFromSampleBuffer: published by Apple in technical QA1702.

like image 118
wobbals Avatar answered Sep 28 '22 12:09

wobbals