Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect orientation of a recorded video in android

Tags:

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.

I tried to grab frame from video file and convert it into jpeg but again it always provides orientation 0 in all cases.

Please help me. Thanks in advance.

like image 817
ultimate Avatar asked Oct 21 '13 05:10

ultimate


People also ask

How can we detect the orientation of the screen in Android?

int orientation = display. getOrientation(); Check orientation as your way and use this to change orientation: setRequestedOrientation (ActivityInfo.

Why is my video sideways on Android?

Open Google Photos on your Android phone and tap the search bar. Choose Videos, then select the video you want to rotate. Tap the slider bar icon (it's at the bottom of the screen in the middle). Select Rotate until the video is oriented the way you want it.

Why does my video play sideways?

This usually happens if you're holding the phone in a way that's not firmly in landscape mode, like if you point the phone down. It can also happen if you open the camera app and start recording before it can change orientation. On other occasions, you may rotate your phone while recording a video.

Can you rotate a video Android?

To rotate a video on Android using a third-party app:Tap Create New Project. Select a video to edit and then tap Create. In the editing menu, scroll through the options at the bottom and tap Transform. Tap the Rotation option.


2 Answers

Api level 17 later, we can extract the orientation of video: MediaMetadataRetriever

MediaMetadataRetriever m = new MediaMetadataRetriever();

m.setDataSource(path);
Bitmap thumbnail = m.getFrameAtTime();
//
if (Build.VERSION.SDK_INT >= 17) {
    String s = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);

    Log.e("Rotation", s);
}
like image 129
Ramesh Akula Avatar answered Sep 28 '22 05:09

Ramesh Akula


FFmpegMediaMetadataRetriever can do this and it works with API 7+:

FFmpegMediaMetadataRetriever fmmr = new FFmpegMediaMetadataRetriever();
fmmr.setDataSource(path);
String rotation = fmmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
Log.e("Rotation", rotation);
fmmr.release();
like image 39
William Seemann Avatar answered Sep 28 '22 05:09

William Seemann