Android MediaMetadataRetriever wrong video height and width

╄→尐↘猪︶ㄣ 提交于 2019-12-12 10:54:38

问题


I want to retrieve height and width of video, I am using MediaMetadataRetriever class for this. It is working correct for most of the case, but for few case height and width are interchanged.

I think this might be happening because of orientation change.

My current code:

MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
        metaRetriever.setDataSource(videoPath);
        videoHeight = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        videoWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);

How can i get correct values? Thank you


回答1:


I've been trying to figure this out myself for the last day or so, I eventually had to solve it experimentally.

            File file = new File(path);
            if (file.exists()) {
                MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                retriever.setDataSource(file.getAbsolutePath());
                String metaRotation = retriever.extractMetadata(METADATA_KEY_VIDEO_ROTATION);
                int rotation = metaRotation == null ? 0 : Integer.parseInt(metaRotation);
                Log.i("Test", "Rotation = " + rotation);
            }

If the rotation is 90 or 270 the width and height will be transposed.



来源:https://stackoverflow.com/questions/45879813/android-mediametadataretriever-wrong-video-height-and-width

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