From 2b51baa1981fb445b938e64bdce539e58fe70264 Mon Sep 17 00:00:00 2001 From: Runt <qingingrunt2010@qq.com> Date: Sat, 26 Jul 2025 13:17:14 +0000 Subject: [PATCH] 小窗缩放, 相机转小窗显示 小窗旋转,相机画面旋转 关闭按钮优化 --- LiveProject/controller/CameraCapture.swift | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/LiveProject/controller/CameraCapture.swift b/LiveProject/controller/CameraCapture.swift index 3345602..355b1e0 100644 --- a/LiveProject/controller/CameraCapture.swift +++ b/LiveProject/controller/CameraCapture.swift @@ -27,19 +27,28 @@ if session.canAddInput(input) { session.addInput(input) } - + let output = AVCaptureVideoDataOutput() output.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA ] output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera.queue")) - if session.canAddOutput(output) { session.addOutput(output) } self.videoOutput = output - + // 在相机配置代码中 + if let videoConnection = output.connection(with: .video) { + // 自动旋转(推荐) + videoConnection.automaticallyAdjustsVideoMirroring = false + videoConnection.videoOrientation = .portrait // 或根据UI方向设置 + + // 对于前置摄像头启用镜像 + /*if videoConnection.isVideoMirroringSupported { + videoConnection.isVideoMirrored = (cameraPosition == .front) + }*/ + } session.commitConfiguration() session.startRunning() print("📷 相机已开启") @@ -51,7 +60,9 @@ guard let buffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } let width = CVPixelBufferGetWidth(buffer) let height = CVPixelBufferGetHeight(buffer) - //print("📷 当前帧尺寸: \(width)x\(height)") + //print("Buffer Size: \(CVPixelBufferGetWidth(buffer))x\(CVPixelBufferGetHeight(buffer))") + //print("Connection orientation: \(connection.videoOrientation.rawValue)") + //print("Rotation angle: \(connection.videoRotationAngle)") onFrame?(buffer) } -- Gitblit v1.9.1