Alex Wulff Alex Wulff - 3 months ago 25
iOS Question

isVideoOrientationSupported always Returns NO AVCaptureConnection

I'm using

AVCaptureMetadataOutput
to detect faces on iOS, and I'm trying to set the orientation of the video after the user rotates their device. However, it appears that I can't do this as every time I call the getter
isVideoOrientationSupported
on the only AVCaptureConnection that my
AVCaptureMetadataOutput
has, it always returns false. I've tried the code below in every place imaginable, yet it always returns no. Is there any way to set orientation for my metadata?

AVCaptureConnection *conn = [self.metadataOutput connectionWithMediaType:AVMediaTypeMetadataObject];

NSLog(@"%@",self.metadataOutput.connections);

if (!conn) {
NSLog(@"NULL CONNECTION OBJ");
}

if ([conn isVideoOrientationSupported]) {
NSLog(@"Supported!");
}

else {
NSLog(@"Not supported");
}

Answer

An Apple Engineer solved this for me over on the Apple Developer Forums. Here's a link. This was their response:

If you want to translate your metadata objects' coordinate space to that of another AVCaptureOutput (such as the AVCaptureVideoDataOutput), use - (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject connection:(AVCaptureConnection *)connection NS_AVAILABLE_IOS(6_0); It's in AVCaptureOutput.h. If you want to translate the coordinates to the coordinate space of your video preview layer, use AVCaptureVideoPreviewLayer.h's - (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject NS_AVAILABLE_IOS(6_0);