0
AVCaptureSession
を使用してビデオを録画するときに、ビデオの向きを変更する必要があります。次のコードを使用して録音を開始する前に向きを変更するようにしましたが、録音処理中に向きを変更する必要があります。AVCapturesessionは、録画中にビデオの向きを変更します。
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[self orientationChanged];
}
//Respond with the rotation
- (void)orientationChanged {
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in [_movieFileOutput connections])
{
NSLog(@"%@", connection);
for (AVCaptureInputPort *port in [connection inputPorts])
{
NSLog(@"%@", port);
if ([[port mediaType] isEqual:AVMediaTypeVideo])
{
videoConnection = connection;
break;
}
}
}
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (deviceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
}
else if (deviceOrientation == UIInterfaceOrientationPortrait) {
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft) {
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
else {
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
}
}