Switching AVCaptureSession preset when capturing a photo

会有一股神秘感。 提交于 2019-12-01 03:45:10

I found the solution for my specific problem. I hope it can be used as a guide if someone stumbles upon the same problem.

The reason why the framerate dropped significantly had to do with an internal conversion between pixel formats. After setting the pixelformat explicitly the framerate increased.

In my situation, I was creating a BGRA texture with the following method:

// Let Core Video create the OpenGL texture from pixelbuffer
CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, videoTextureCache, pixelBuffer, NULL,
                                                            GL_TEXTURE_2D, GL_RGBA, width, height, GL_BGRA,
                                                            GL_UNSIGNED_BYTE, 0, &videoTexture);

So when I setup the AVCaptureStillImageOutput instance I changed my code to:

// Add still output
stillOutput = [[AVCaptureStillImageOutput alloc] init];
[stillOutput setOutputSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];

if([captureSession canAddOutput:stillOutput])
{
    [captureSession addOutput:stillOutput];
}
else
{
    NSLog(@"Couldn't add still output");
}

I hope this helps someone someday ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!