iPhone: Toggling front/back AVCaptureDeviceInput camera when processing individual frames via setSampleBufferDelegate

StackOverflow https://stackoverflow.com//questions/9662897

Question

I've run into an interesting issue when I attempt to switch from using the front camera to using the back camera while processing individual frames via the AVCaptureVideoDataOutput:setSampleBufferDelegate selector. The camera swap works and the preview screen that I'm displaying looks great, it's just that the resulting frames that I capture are no longer in portrait mode, they are in landscape. Also, swapping from the front then back to the back camera will result in the back camera capturing landscape frames. I suspect that since this is the case something is getting screwed up when I swap out the input - it's not the input that's incorrect. I verified this theory by starting the AVCaptureSession with the front facing camera - the frames passed to the buffer delegate are correctly in portrait mode. I've also played with explicitly stopping the AVCaptureSession while the device input is being swapped with no difference in results.

I cribbed from the AVCam demo for inspiration. The suspicious difference between that code and mine is that it records to an AVCaptureMovieFileOutput - it's not processing individual frames.

Any ideas? Why would the orientation of the frames sent to my processor change when I swap out the device input?

Thanks for any response!

Was it helpful?

Solution

Ah ha! I figured it out. For some reason after switching the device input my video output's AVCaptureConnection was getting its orientation reset to landscape-right. To solve the problem, after I swap the input I explicitly ask the video output's AVCaptureConnection to set its orientation to portrait.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top