首页 > 解决方案 > 使用 OpenGL 的视频帧旋转

问题描述

我正在将视频帧旋转到 0 到 360 之间的任意角度,因为我使用 OpenGL 旋转帧并将视频旋转到任意角度,但问题是在保存视频后,它的视图被拉伸,就像这个 45 度链接旋转带有拉伸角的视频示例帧图像, 但我希望此结果旋转视频帧图像,并带有 我正在使用的完美 45 度代码示例,请检查

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

请帮我找出完美的解决方案,任何帮助将不胜感激

标签: androidopengl-esandroid-cameravideo-processing

解决方案


要对 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);

推荐阅读