使用矩阵rotateM()从表面纹理,但腐败的视频输出旋转矩阵 [英] Use rotateM() of Matrix to rotate matrix from SurfaceTexture but corrupt the video output
问题描述
我设法与OpenGL ES的播放视频,我用grafika的ContinuousCaptureActivity的方式,我的数据源是MediaPlayer的,而不是相机,这没什么区别。
MediaPlayer的不断产生视频帧和我绘制onFrameAvailable回调每一帧屏幕。在code是如下效果很好:
I managed to play video with opengl es, I used the way of grafika's ContinuousCaptureActivity, my data source is MediaPlayer rather than Camera which makes no difference. MediaPlayer produces video frames continuously and I draw each frame to screen in onFrameAvailable callback. The code is as follows which works well:
mVideoTexture.updateTexImage();
mVideoTexture.getTransformMatrix(mTmpMatrix);
mDisplaySurface.makeCurrent();
int viewWidth = getWidth();
int viewHeight = getHeight();
GLES20.glViewport(0, 0, viewWidth, viewHeight);
mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
mDisplaySurface.swapBuffers();
现在我想用270度旋转的视频帧,所以我改变了code:
Now I want to rotate video frames with 270 degrees, so I changed the code:
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
mVideoTexture.updateTexImage();
mVideoTexture.getTransformMatrix(mTmpMatrix);
mDisplaySurface.makeCurrent();
int viewWidth = getWidth();
int viewHeight = getHeight();
GLES20.glViewport(0, 0, viewWidth, viewHeight);
Matrix.rotateM(mTmpMatrix, 0, 270, 1f, 0, 0);
mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
mDisplaySurface.swapBuffers();
不过,我可以与下面的code成功翻转视频帧:
But I can flip video frame successfully with the code below:
mVideoTexture.updateTexImage();
mVideoTexture.getTransformMatrix(mTmpMatrix);
mDisplaySurface.makeCurrent();
int viewWidth = getWidth();
int viewHeight = getHeight();
GLES20.glViewport(0, 0, viewWidth, viewHeight);
mTmpMatrix[5] = -1 * mTmpMatrix[5];
mTmpMatrix[13] = 1.0f - mTmpMatrix[13];
mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);
mDisplaySurface.swapBuffers();
如何实现旋转,任何人都可以给我一些帮助吗?
How to achieve the rotation, Could anyone give me some help?
地址:
首先,我想告诉大家,我一直用这个code为每次抽奖行动:
At first, I want to tell that I always used this code for each draw action:
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
我用这个演示做我的测试,这是本次测试的很好的演示。
https://github.com/izacus/AndroidOpenGLVideoDemo
该矩阵从得到表面纹理是:
The matrix got from the surfacetexture is:
1.0,0.0,0.0,0.0
1.0, 0.0, 0.0, 0.0
0.0,-1.0,0.0,0.0
0.0, -1.0, 0.0, 0.0
0.0,0.0,1.0,0.0
0.0, 0.0, 1.0, 0.0
0.0,1.0,0.0,1.0
0.0, 1.0, 0.0, 1.0
在Matrix.setRotateM(videoTextureTransform,0,270,0,0,1);,
After "Matrix.setRotateM(videoTextureTransform, 0, 270 , 0, 0, 1);",
成为:
1.1924881E-8,-1.0,0.0,0.0
1.1924881E-8, -1.0, 0.0, 0.0
1.0,1.1924881E-8,0.0,0.0
1.0, 1.1924881E-8, 0.0, 0.0
0.0,0.0,1.0,0.0
0.0, 0.0, 1.0, 0.0
0.0,0.0,0.0,1.0
0.0, 0.0, 0.0, 1.0
推荐答案
需要法登的绕z轴的旋转矩阵所应遵循的正确翻译,使其回到屏幕上,可以这么说。我测试下的所有3个旋转的视频表面纹理:
fadden's rotation matrix about the z-axis needs to be followed by the correct translation to bring it back on-screen, so to speak. I've tested all 3 rotations below on SurfaceTexture video:
旋转90度
Matrix.rotateM(mTmpMatrix, 0, 90, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, 0, -1, 0);
旋转180
Matrix.rotateM(mTmpMatrix, 0, 180, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, -1, 0);
旋转270
Matrix.rotateM(mTmpMatrix, 0, 270, 0, 0, 1);
Matrix.translateM(mTmpMatrix, 0, -1, 0, 0);
这篇关于使用矩阵rotateM()从表面纹理,但腐败的视频输出旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!