diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-09-10 10:11:03 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-09-10 11:24:16 +0200 |
commit | 62e92cf60bfd43dba4a9910453aec9489daa9d36 (patch) | |
tree | 41503b1f107bcae8251962b3bba47b3f839f843a /src/multimedia | |
parent | 782a682be989e0738dff4ce25021e275cb92ff60 (diff) |
Fix aspect ratio of recordings on iOS
When recording in portrait mode, ensure that the video size
that we ask from the recorder is also in portrait.
Pick-to: 6.2 6.2.0
Change-Id: Ibca58d03fd69da637576e20cfd8ecaa484faa8fe
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/platform/darwin/avfvideosink_p.h | 2 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/camera/avfmediaencoder.mm | 32 |
2 files changed, 16 insertions, 18 deletions
diff --git a/src/multimedia/platform/darwin/avfvideosink_p.h b/src/multimedia/platform/darwin/avfvideosink_p.h index 522c8118d..4227bcb53 100644 --- a/src/multimedia/platform/darwin/avfvideosink_p.h +++ b/src/multimedia/platform/darwin/avfvideosink_p.h @@ -105,6 +105,7 @@ public: void updateLayerBounds(); void nativeSizeChanged() { updateLayerBounds(); } + QSize nativeSize() const { return m_sink->nativeSize(); } CVMetalTextureCacheRef cvMetalTextureCache = nullptr; #if defined(Q_OS_MACOS) @@ -116,7 +117,6 @@ private: void freeTextureCaches(); protected: - QSize nativeSize() const { return m_sink->nativeSize(); } AVFVideoSink *m_sink = nullptr; QRhi *m_rhi = nullptr; diff --git a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm index 875074c28..c34503277 100644 --- a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm +++ b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm @@ -242,7 +242,7 @@ static NSDictionary *avfAudioSettings(const QMediaEncoderSettings &encoderSettin return settings; } -NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCaptureDevice *device, AVCaptureConnection *connection) +NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCaptureDevice *device, AVCaptureConnection *connection, QSize nativeSize) { if (!device) return nil; @@ -328,12 +328,21 @@ NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCapture w += w & 1; h += h & 1; - [videoSettings setObject:[NSNumber numberWithInt:w] forKey:AVVideoWidthKey]; - [videoSettings setObject:[NSNumber numberWithInt:h] forKey:AVVideoHeightKey]; + bool isPortrait = nativeSize.width() < nativeSize.height(); + // Make sure the video has the right aspect ratio + if (isPortrait && h < w) + qSwap(w, h); + else if (!isPortrait && w < h) + qSwap(w, h); + encoderSettings.setVideoResolution(QSize(w, h)); } else { - encoderSettings.setVideoResolution(qt_device_format_resolution(device.activeFormat)); + w = nativeSize.width(); + h = nativeSize.height(); + encoderSettings.setVideoResolution(nativeSize); } + [videoSettings setObject:[NSNumber numberWithInt:w] forKey:AVVideoWidthKey]; + [videoSettings setObject:[NSNumber numberWithInt:h] forKey:AVVideoHeightKey]; // -- FPS @@ -407,7 +416,8 @@ void AVFMediaEncoder::applySettings(QMediaEncoderSettings &settings) return; const AVFConfigurationLock lock(device); // prevents activeFormat from being overridden AVCaptureConnection *conn = [session->videoOutput()->videoDataOutput() connectionWithMediaType:AVMediaTypeVideo]; - m_videoSettings = avfVideoSettings(settings, device, conn); + auto nativeSize = session->videoOutput()->nativeSize(); + m_videoSettings = avfVideoSettings(settings, device, conn, nativeSize); if (m_videoSettings) [m_videoSettings retain]; } @@ -479,18 +489,6 @@ void AVFMediaEncoder::record(QMediaEncoderSettings &settings) QMediaRecorderPrivate::msgFailedStartRecording()); return; } - - // 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). - // QCameraDevice cameraDevice = m_service->session()->activecameraDevice(); - // int screenOrientation = 360 - m_orientationHandler.currentOrientation(); - - // ### - // if (cameraDevice.position() == QCameraDevice::FrontFace) - // rotation = (screenOrientation + cameraDevice.orientation()) % 360; - // else - // rotation = (screenOrientation + (360 - cameraDevice.orientation())) % 360; } const QString path(outputLocation().scheme() == QLatin1String("file") ? |