AVCaptureSession旋转| 视频传输时的方向

Ami*_*k12 4 video objective-c++ ios avcapturesession avcapturedevice

我正在开发视频流应用,其中我需要捕获前置摄像头视频帧并编码然后转移到另一端,典型的流程是这样的

AVCaptureSession - > AVCaptureDeviceInput - > AVCaptureVideoDataOutput - >捕获帧 - >编码帧 - >发送帧到另一端,

它工作正常,我已将kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange设置为帧格式.

还有用于显示预览的预览图层,

当设备方向发生变化时,问题就出现了,如果设备从纵向移动到横向,那么在另一端框架旋转90度,我期待自从预览层支持方向,所以我将在Capture回调中自动接收旋转缓冲区,但看起来,预览层只显示捕获的缓冲区的预览和UI orating缓冲区,而在另一端我会得到咆哮的缓冲区,

所以我想知道,有没有任何配置可以让它改变,或者我需要在Capture缓冲区回调中旋转/转换缓冲区.

Ami*_*k12 8

感谢您查看它,基本上解决方案是,应该设置连接方向,并且我正在使用预览图层,因此它会影响预览图层但不会影响方向.

这里是代码片段

-(void) orientationChanged
{
    // get the new orientation from device 
    AVCaptureVideoOrientation newOrientation = [self videoOrientationFromDeviceOrientation];

    // set the orientation of preview layer :( which will be displayed in the device )
    [previewLayer.connection setVideoOrientation:newOrientation];

    // set the orientation of the connection: which will take care of capture
    [pCaptureConnection setVideoOrientation:newOrientation];

}
Run Code Online (Sandbox Code Playgroud)

  • 什么是 pCaptureConnection? (3认同)