如何设置AVCaptureFileOutput的方向?

时间:2014-10-09 07:55:41

标签: ios objective-c cocoa-touch

如何设置AVCaptureFileOutput的方向?我指的是最终输出,它必须是风景。

1 个答案:

答案 0 :(得分:0)

设置相机时,您有AVCaptureVideoDataOutput videoDataOutput和AVCaptureVideoPreviewLayer previewLayer。您可以通过以下方式配置它们。

//set the orientation of previewlayer, which is presented to user
AVCaptureConnection *conncetion = self.previewLayer.connection;
conncetion.videoOrientation = AVCaptureVideoOrientationLandscapeRight;

//set the output frame orientation
AVCaptureConnection *conn = [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
conn.videoOrientation = AVCaptureVideoOrientationLandscapeRight;

在AVCam示例代码中,录制并保存为文件时。以上两个设置为相同的方向,即viewcontroller的interfaceOrientation:

[[[self movieFileOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

它观察设备方向,这很好。