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();
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();
But the result is weird, take a look at the picture below:
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?
ADD:
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);
I use this demo to do my test, it is a very good demo for this test.
https://github.com/izacus/AndroidOpenGLVideoDemo
The matrix got from the surfacetexture is:
1.0, 0.0, 0.0, 0.0
0.0, -1.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 1.0, 0.0, 1.0
After "Matrix.setRotateM(videoTextureTransform, 0, 270 , 0, 0, 1);",
it became:
1.1924881E-8, -1.0, 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, 0.0, 1.0
And this video effect is:
See Question&Answers more detail:
os