AVCaptureSession rotate | orientation while video transmitting

无人久伴 提交于 2019-12-05 01:43:21

问题


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 -> capture frame --> encode frame --> send frame to other end,

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

also preview layer being used to show the preview,

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,

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.


回答1:


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.

here goes the code snippet

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

}


来源:https://stackoverflow.com/questions/26236093/avcapturesession-rotate-orientation-while-video-transmitting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!