saberpowermo
saberpowermo

Reputation: 1

How can I get The Video stream's info when use android MediaPlayer, the info like SAR and DAR

everyVideo has Stream info, like this. --> #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 576x432 [SAR 1:1 DAR 4:3]

I used MediaPlayer to play a video, Like this.

MediaPlayer mInternalMediaPlayer = new MediaPlayer();
mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mInternalMediaPlayer.setDataSource(source);
mInternalMediaPlayer.prepareAsync();

and i want get the video's storage aspect ratio to compute the display aspect ratio, how can i do it ?

Upvotes: 0

Views: 301

Answers (1)

Mick
Mick

Reputation: 25471

The storage aspect ratio is the ratio of horizontal to vertical pixels in the video.

So a video which is 1280x720 has a SAR of 16:9, a video which is 640 × 480 has a SAR of 4:3 and so on.

The DAR is the display aspect ratio - if they match then displaying the video is easier. If they don't match then the pixels need to be 'squashed' or distorted to display the video and the degree to which they are distorted is Pixel Aspect Ratio.

They are be related like this:

  • PAR = DAR/SAR

Hence, to get the storage aspect ratio all you need is the regular video aspect ratio.

You can get this using the 'MediaMetadataRetriever' object: https://developer.android.com/reference/android/media/MediaMetadataRetriever.html

An example is:

MediaMetadataRetriever videoMetaRetriever = new MediaMetadataRetriever();


String videoWidth = videoMetaRetriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);

String videoHeight = videoMetaRetriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);

Upvotes: 1

Related Questions