android - 使用 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);
请帮我找出完美的解决方案,任何帮助将不胜感激
解决方案
要对 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);
推荐阅读
- javascript - 这段代码有什么问题,它说 listen EADDRINUSE: address already in use 127.0.0.1:8080
- node.js - 如何从子进程脚本运行打包的可执行 node.js 应用程序?
- java - 通过java从另一台机器连接MySQL数据库
- java - 如何从字符串中分离许多不同的单词(Java)
- xslt - xsl 选取以下兄弟姐妹的文本值
- azure - 从本地机器连接天蓝色数据库容器?
- php - 如何在 Laravel 5.6 中重定向到以前的 URL 和预期
- clojure - Clojure:doseq 函数从上到下打印数字范围
- r - R Mojave 模糊石英窗
- swift - 无法从 Firebase 查看字典数据