Inconsistent video rotation when using MediaCodec

左心房为你撑大大i 提交于 2020-01-13 06:46:45

问题


I have two devices, a Nexus 7 (Android 5) and a Galaxy S3 (4.3). On both devices I recorded a video in portrait mode and saved it with rotation hint 90 degrees. This is the correct orientation hint cause when played using the default media player the orientation is fine on both devices. I can even copy the video from the Nexus to the Galaxy and the orientation is still fine when I play the video file.

However, when I decode the video using the MediaCodec api I get some problems with the video rotation. When I display the video data I get from the MediaCodec the video on the Nexus is correct but on the Galaxy S3 the video is rotated by 90 degrees. My problem is that I have no clue what parameters on both devices differ so that I can decide why I have to rotate the video on the Galaxy but not on the Nexus!

On both devices the display rotation is 0 and the orientation is portrait: int rotation = windowManager.getDefaultDisplay().getRotation(); int orientation = context.getResources().getConfiguration().orientation;

Is there another parameter I have to take into account?

Was there some api changes between 4.3 and 5 that affects the rotation of the decoded video? For example, is that video rotated automatically now?

I use opengl to display the video in case it matters...

Update: Solution

The problem was in the OpenGL transformation matrix that I get back from the MediaCodec. MediaCodec renders onto a SurfaceTexture and in case of the Nexus the transformation matrix of the SurfaceTexture is updated correctly, the Galaxy does not do that. When rendering the final output texture I used this matrix. To solve this I ignore the transformation matrix and rotate the video manually according to the recording hint.

来源:https://stackoverflow.com/questions/29518560/inconsistent-video-rotation-when-using-mediacodec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!