So, I followed Apple's instructions to capture video session using AVCaptureSession
: http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html. One problem I'm facing is that even though the orientation of the camera / iPhone device is vertical (and the AVCaptureVideoPreviewLayer
shows a vertical camera stream), the output image seems to be in the landscape mode. I checked the width and height of imageBuffer inside imageFromSampleBuffer:
of the sample code, and I got 640px and 480px respectively. Does anyone know why this's the case?
Thanks!
Take a look at the header AVCaptureSession.h. There is a definition for an enum called AVCaptureVideoOrientation
that defines various video orientations. On the AVCaptureConnection object there is a property called videoOrientation that is a AVCaptureVideoOrientation
. You should be able to set this to change the orientation of the video. You probably want AVCaptureVideoOrientationLandscapeRight
or AVCaptureVideoOrientationLandscapeLeft
.
You can find the AVCaptureConnections for the session by looking at the outputs for the session. The outputs have a connections property that is an array of connections for that output.
Y'all are making this difficult.
In the DidOutputSampleBuffer, simply change the orientation before you grab the image. It's mono, but you have
public class OutputRecorder : AVCaptureVideoDataOutputSampleBufferDelegate {
public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
{
try {
connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft;
in objC it's this method
- ( void ) captureOutput: ( AVCaptureOutput * ) captureOutput
didOutputSampleBuffer: ( CMSampleBufferRef ) sampleBuffer
fromConnection: ( AVCaptureConnection * ) connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With