在android中检测录制视频的方向 [英] Detect orientation of a recorded video in android
问题描述
我想让我的自定义媒体播放器,并要求视频的方向信息(用于检测它是从前面或后面的相机记录)。对于jpeg图像,我可以使用 ExifInterface.TAG_ORIENTATION
,但对于视频,我可以找到这些信息。
I want to make my custom media player and requires orientation info of video (for detecting it is recorded from front or back camera). for jpeg images i can use ExifInterface.TAG_ORIENTATION
but for video how i can find this information.
我试图从视频文件抓取框架并将其转换为jpeg,但是在所有情况下,它总是提供方向 0
。
I tried to grab frame from video file and convert it into jpeg but again it always provides orientation 0
in all cases.
请帮我。感谢提前。
推荐答案
经过太多的努力,我知道媒体播放器提供视频文件的高度和宽度,从中我们可以拍摄视频的旋转。
After too much effort i came to know that media player provides height and width of video file from which we can fin out rotation of video.
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(viewSource);
mp.prepare();
mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
int orientation = -1;
if(width < height){
orientation = 0;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}
else{
orientation = 1;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
这篇关于在android中检测录制视频的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!