4

I am working on a rotation of video frames to any degree between 0 to 360 for that I used OpenGL to rotate frames and get rotate the video to any degrees but the problem is after saving the video its view is stretched like this 45 degrees link rotated video sample frame image with stretch corner but I want this result rotated video frame image with a perfect 45 degrees code sample that I'm using please check

import android.opengl.Matrix; 
private float[] MVPMatrix = new float[16];
Matrix.setRotateM(MVPMatrix, 0, 45, 0, 0, -1.0f);

please help me to find out the perfect solution, Any help will be appreciated

genpfault
  • 51,148
  • 11
  • 85
  • 139
Sara Khan
  • 41
  • 5

1 Answers1

0

to apply rotation/scale/translation to MVPMatrix you should setup projection matrix first (width, height - size of result video)

GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
Matrix.orthoM(mMVPMatrix, 0, -ratio, ratio, -1, 1, -1, 1);

Then, you need to apply transformations to model matrix

Matrix.translateM(mTranslateMatrix, 0, dx, dy, 0);
mTempMatrix = mModelMatrix.clone();
Matrix.multiplyMM(mModelMatrix, 0, mTempMatrix, 0, mTranslateMatrix, 0);

Matrix.setRotateM(mRotationMatrix, 0, rotation, 0, 0, -1.0f);
mTempMatrix = mModelMatrix.clone();
Matrix.multiplyMM(mModelMatrix, 0, mTempMatrix, 0, mRotationMatrix, 0);

Matrix.scaleM(mScaleMatrix, 0, scaleX, scaleY, 1);
mTempMatrix = mModelMatrix.clone();
Matrix.multiplyMM(mModelMatrix, 0, mTempMatrix, 0, mScaleMatrix, 0);

And finally apply model matrix to MVPMatrix

mTempMatrix = mMVPMatrix.clone();
Matrix.multiplyMM(mMVPMatrix, 0, mTempMatrix, 0, mModelMatrix, 0);