使用 OpenGL 的视频帧旋转

Posted

技术标签:

【中文标题】使用 OpenGL 的视频帧旋转【英文标题】:Video Frame Rotation Using OpenGL 【发布时间】:2019-03-10 15:24:24 【问题描述】:

我正在将视频帧旋转到 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);

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

【问题讨论】:

这个链接可以帮助你this 谢谢,但对我没有帮助,请提出其他建议 【参考方案1】:

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

【讨论】:

以上是关于使用 OpenGL 的视频帧旋转的主要内容,如果未能解决你的问题,请参考以下文章

ffmpeg 视频到 opengl 纹理

使用Quaternion问题的C ++ OpenGl Camera旋转

使用 OpenGL 的 2D Sprite 动画技术

在 iPhone 上使用 CADisplayLink 在 OpenGL ES 视图中进行等速旋转

来自 OpenGL 的 CMSampleBuffer,用于使用 AVAssestWritter 进行视频输出

有没有办法直接从GLSurfaceView(OpenGL ES)创建视频文件?