AVCaptureSession旋转|视频传输时的方向 [英] AVCaptureSession rotate | orientation while video transmitting

查看:854
本文介绍了AVCaptureSession旋转|视频传输时的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing video streaming application, in which i need to capture front camera video frame and encode then transfer to other end, a typical flow is like this

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

AVCaptureSession -> AVCaptureDeviceInput -> AVCaptureVideoDataOutput -> capture frame --> encode frame --> send frame to other end,

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

it works fine, i have setup the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange as a frame format.

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

also preview layer being used to show the preview,

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

the problem comes when device orientation gets changes, if device moved from portrait to landscape, then on the other end frames gets rotate by 90, i was expecting since orientation being supported in the preview layer so i will automatically received rotated buffer in the Capture callback, but it looks like, preview layer just show me the preview of the buffer captured and UI orates the buffer, while on the other end i would get the roared buffer,

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

So i want to know, Are there any configuration to make it change , or do i need to rotate/transform buffer in the Capture buffer callback.

推荐答案

感谢您查看,基本上解决方案是,应该设置连接方向,我正在播放预览图层,因此它影响预览图层但不影响方向。

Thanks for looking into it, basically the solution is, orientation of connection should be set, and i was playing with the preview layer, so its affecting the preview layer but not the orientation.

这里是代码片段

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

}

这篇关于AVCaptureSession旋转|视频传输时的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆