安卓:恩codeD相机preVIEW帧总是景观。如何旋转? [英] Android: Encoded Camera Preview Frames always in landscape. How to rotate?

查看:208
本文介绍了安卓:恩codeD相机preVIEW帧总是景观。如何旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:流Android相机,以适当的取向Wowza服务器不管设备的定向(即,视频总是右侧上)

Goal: Streaming Android Camera to Wowza Server in proper orientation no matter the orientation of device (i.e. the video is always right side up)

我看了所有的问题就在这里有关相机方位,到目前为止,他们似乎都只是改变其呈现到屏幕或MP4文件设置标志(不适合我使用preVIEW案例:流媒体)。

I've looked at all the questions on here regarding camera orientation and so far they all seem to just change the preview which is rendered to the screen or set a flag in the MP4 file (not appropriate for my use case: streaming).

我流摄像帧到Wowza服务器和Wowza服务器上接收到的视频始终是景观。这是好的,如果手机处于相同的方向始终认为,但我不能保证我的用户会做到这一点。从我收集的,当你直接从相机抢框架和它们提供给EN codeR,你所得到的设备的摄像头的自然方位(可安装在我的情况景观),这是完全由preVIEW不受影响。因为如果该装置在流期间旋转时,图像与它旋转,这是有问题的。

I'm streaming camera frames to a Wowza server and on the Wowza server the received video is always landscape. This is fine if the phone is always held in the same orientation but I can't guarantee my users will do this. From what I've gathered, when you grab frames directly from the camera and feed them to the encoder, you are getting the natural orientation of the device's camera (which may be mounted landscape in my case) and this is completely unaffected by the preview. This is problematic because if the device is rotated during the stream, the image is rotated with it.

我已经用openGL矩阵变换preVIEW在自定义GLSurfaceView.Renderer审判,它是所有改变屏幕上的视图,而不是发送到EN codeR帧。

I have tried using openGL matrix to transform the preview in a custom GLSurfaceView.Renderer and all it does is transform the View on the screen, not the frames sent to the encoder.

我已经读了Grafika的例子,我不知道从哪里在这个过程中,我需要他们被送到EN codeR前旋转帧。我使用的是作为表面纹理相机preVIEW,然后渲染到GLSurfaceView(并使用自己的定制GLSurfaceView.Renderer)。

I have read over Grafika's examples and am not sure where in the process I need to rotate frames before they are fed to the encoder. I am using a SurfaceTexture as a camera preview which is then rendered to a GLSurfaceView (and using my own custom GLSurfaceView.Renderer).

我怎么可以旋转架的EN codeR?

How can I rotate the frames to the encoder?

在理想情况下,我会做这在OpenGL。我曾想过灌装媒体codec.dequeueInputBuffer缓存前旋转框架,但这将使用CPU来完成,我因为实时应用的很谨慎。也许我可以俯瞰与问候到preVIEW东西。我见过的其他广播应用推倒preVIEW层上的用户界面和重建它,每当设备旋转。

Ideally I would do this in openGL. I had thought about rotating the frames before filling mediacodec.dequeueInputBuffer buffers but this will be done using the CPU and I'm wary because of the real-time application. Maybe I am overlooking something with regards to the preview. I've seen other broadcasting applications tear down the Preview layer on the UI and rebuild it whenever the device is rotated.

参考文献:

https://github.com/Kickflip/kickflip-android-sdk/

https://github.com/google/grafika

推荐答案

在Grafika相机活动渲染每一帧两次:一次显示,一旦进行编码。你想要做同样的事情,但在旋转投掷(和进行适当的调整,以媒体codeC / MediaRecorder配置,即720x1280与1280×720)。

The camera Activities in Grafika render every frame twice: once for the display, and once for encoding. You want to do the same thing, but throw in a rotation (and make an appropriate adjustment to the MediaCodec / MediaRecorder configuration, i.e. 720x1280 vs. 1280x720).

例如,考虑<一个href=\"https://github.com/google/grafika/blob/master/src/com/android/grafika/ContinuousCaptureActivity.java#L409\"相对=nofollow> 并条机()在ContinuousCapture 方法。它选择SurfaceView的EGLSurface,绘制,然后切换到视频连接codeR的EGLSurface和调用相同的绘制方法。它甚至抛出调用 drawExtra()只是为了表明它可以了。

For example, consider the drawFrame() method in ContinuousCapture. It selects the SurfaceView's EGLSurface, draws, then switches to the video encoder's EGLSurface and calls the same draw method. It even throws in a call to drawExtra() just to show that it can.

在这两种情况下,你只是渲染GLES到一个EGLSurface和EGLSurface从底层的表面,这无论是从SurfaceView或媒体codeC来获取其尺寸。如果修改 FullFrameRect#并条机()采取矩阵参数,并在旋转矩阵传到位了目前使用的单位矩阵,你应该得到你想要的结果

In both cases you're just rendering GLES onto an EGLSurface, and the EGLSurface gets its dimensions from the underlying Surface, which either came from SurfaceView or MediaCodec. If you modify FullFrameRect#drawFrame() to take a matrix argument, and pass in a rotation matrix in place of the identity matrix it currently uses, you should get the result you want.

这篇关于安卓:恩codeD相机preVIEW帧总是景观。如何旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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