问题描述
只需尝试解码视频中的帧.在使用Android 4+(< 5)时,它可以正常工作.我正在使用示例的一部分,可以在这里找到: http://bigflake.com/mediacodec/"ExtractMpegFramesTest.java(需要4.1,API 16)"
Simply trying to decode frames from videos.While working with Android 4+ (<5), it worked just fine.I'm using parts of the example that can be found here:http://bigflake.com/mediacodec/"ExtractMpegFramesTest.java (requires 4.1, API 16)"
问题是-它提取了一个帧,但是结果位图如下所示(解码后立即保存了图像):
The problem is - it extracts a frame, but the result Bitmap is as can be seen here (Saved an image right after decoding it):
真实视频当然具有真实"帧,而不是拉伸" 1列.
The real video of course has "real" frames, and not "stretched" 1 column.
我已经在代码行之后保存了这张图片:
I've saved this image right after the code line:
bmp.copyPixelsFromBuffer(mPixelBuf);
// <-- here I saved the above image
解决这个问题的解码器是否有一些重大更新(我找不到)?
Is there some major update (I can't find) to the decoder that solves this ?
推荐答案
在API级别21及更高级别上,解码器在渲染到表面时会应用旋转.因此,从SurfaceTexture获得的transformMatrix包含旋转信息,这意味着示例中用于反转SurfaceTexture的方法不起作用.为了正确地反转纹理,我将其旋转到z轴并进行x,y轴变换.以下是我的工作:
On API level 21 and above the decoder applies the rotation when rendering to the surface. Therefore, the transformMatrix you got from SurfaceTexture contains the rotation info, which means the way use to invert the SurfaceTexture in the example doesn't work. To correctly invert the texture, I rotation it by z axis and do x, y axis transform. Following are what I do :
chnage
st.getTransformMatrix(mSTMatrix);
if (invert) {
mSTMatrix[5] = -mSTMatrix[5];
mSTMatrix[13] = 1.0f - mSTMatrix[13];
}
到
st.getTransformMatrix(mMatrix);
if(invert){
Matrix.setIdentityM(identifyMatrix, 0);
Matrix.translateM(identifyMatrix, 0, 1, 1, 0);
Matrix.rotateM(identifyMatrix, 0, 180, 0, 0, 1);
Matrix.multiplyMM(mSTMatrix, 0, identifyMatrix, 0, mMatrix,0);
}
其中mMatrix和identifyMatrix都是
where mMatrix and identifyMatrix are both
new float[16];
这篇关于在Android 5+中使用MediaCodec损坏的视频解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!