summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2016-02-09 23:44:33 +0100
committerYoann Lopes <yoann.lopes@qt.io>2016-06-13 13:20:42 +0000
commitc6a8c2c846e8f4305aca05be662172e55d5fb674 (patch)
treed5e0aaed09c6efc6b2e8b2f852675aa0a13c9cba /src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
parentf5de14107094080f15fad3beffb64ad95ff6c5e4 (diff)
AVFoundation: fix orientation of recorded videos.
Make sure the video is recorded in the same orientation as the device. That means the top of the video matches the physical side of the device which is on top when starting recording. This patch makes sure the behavior is the same as on Android. In a future version, we should have an API to pick the desired orientation of the recorded video. Change-Id: Ia8bbfe621a0e54de3cb6bfe0a520f37e8a932539 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm')
-rw-r--r--src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm b/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
index f2c16f675..e65c98257 100644
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
+++ b/src/plugins/avfoundation/camera/avfmediarecordercontrol_ios.mm
@@ -262,9 +262,26 @@ void AVFMediaRecorderControlIOS::setState(QMediaRecorder::State state)
applySettings();
- if ([m_writer setupWithFileURL:nsFileURL cameraService:m_service
- audioSettings:m_audioSettings
- videoSettings:m_videoSettings]) {
+ // Make sure the video is recorded in device orientation.
+ // The top of the video will match the side of the device which is on top
+ // when recording starts (regardless of the UI orientation).
+ AVFCameraInfo cameraInfo = m_service->session()->activeCameraInfo();
+ int screenOrientation = 360 - m_orientationHandler.currentOrientation();
+ float rotation = 0;
+ if (cameraInfo.position == QCamera::FrontFace)
+ rotation = (screenOrientation + cameraInfo.orientation) % 360;
+ else
+ rotation = (screenOrientation + (360 - cameraInfo.orientation)) % 360;
+
+ // convert to radians
+ rotation *= M_PI / 180.f;
+
+ if ([m_writer setupWithFileURL:nsFileURL
+ cameraService:m_service
+ audioSettings:m_audioSettings
+ videoSettings:m_videoSettings
+ transform:CGAffineTransformMakeRotation(rotation)]) {
+
m_state = QMediaRecorder::RecordingState;
m_lastStatus = QMediaRecorder::StartingStatus;