我正在将视频帧旋转到0到360之间的任意角度,因为我使用OpenGL旋转帧并将视频旋转到任意角度,但是问题是保存视频后,其视图像这样拉伸了45度链接rotated video sample frame image with stretch corner,但我需要我正在使用的此结果rotated video frame image with a perfect 45 degrees代码示例,请检查
import android.opengl.Matrix;
private float[] MVPMatrix = new float[16];
Matrix.setRotateM(MVPMatrix, 0, 45, 0, 0, -1.0f);
请帮助我找出完美的解决方案,任何帮助将不胜感激
答案 0 :(得分:0)
要将旋转/缩放/平移应用于 MVPMatrix,您应该首先设置投影矩阵(宽度、高度 - 结果视频的大小)
GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
Matrix.orthoM(mMVPMatrix, 0, -ratio, ratio, -1, 1, -1, 1);
然后,您需要对模型矩阵进行转换
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);
最后将模型矩阵应用到MVPMatrix
mTempMatrix = mMVPMatrix.clone();
Matrix.multiplyMM(mMVPMatrix, 0, mTempMatrix, 0, mModelMatrix, 0);