首页 > 解决方案 > 为什么 iOS 上的默认 webrtc 视频捕获器方向是 90°?

问题描述

调查后RTCCameraVideoCapturer.m我发现了这个:

- (void)captureOutput:(AVCaptureOutput *)captureOutput
   didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
          fromConnection:(AVCaptureConnection *)connection {
  
  #if TARGET_OS_IPHONE
  
  switch (_orientation) {
    case UIDeviceOrientationPortrait:
      _rotation = RTCVideoRotation_90;
      break;
    case UIDeviceOrientationPortraitUpsideDown:
      _rotation = RTCVideoRotation_270;
      break;
    case UIDeviceOrientationLandscapeLeft:
      _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0;
      break;
    case UIDeviceOrientationLandscapeRight:
      _rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180;
      break;
  }
  #else
    // No rotation on Mac.
    _rotation = RTCVideoRotation_0;
  #endif
}

为什么默认相机捕捉器的方向是 90°。我制作了一个简单的 voip 客户端,即使设备处于纵向模式,我 iPhone 上的视频也看起来是旋转的。我在这里想念什么?有什么方法可以旋转捕获器的视频方向。

任何想法表示赞赏

标签: iosxcodewebrtcvideo-capture

解决方案


检查AVCaptureConnection.videoOrientation

https://developer.apple.com/documentation/avfoundation/avcaptureconnection/1389415-videoorientation

我猜原始方向取决于相机制造商。为了向客户端提供最大速度,图像数据直接从传感器缓冲区传输。您无法旋转捕获器的视频方向。您只能混合视频和界面方向属性以正确地呈现给用户。


推荐阅读