4

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

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

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

也用于显示预览的预览层,

当设备方向发生变化时问题出现,但看起来,预览层只是向我展示了捕获的缓冲区的预览,并且 UI 对缓冲区进行了渲染,而在另一端我会得到咆哮的缓冲区,

所以我想知道,是否有任何配置可以使其更改,或者我是否需要在捕获缓冲区回调中旋转/转换缓冲区。

4

1 回答 1

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];

}
于 2014-10-08T10:39:49.783 回答