Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the resolution of a video in Android?

I'm looking for a way to get the resolution of any given video in Android. It doesn't have to work with other formats than the ones supported in Android, but it'd be great if it did. If you're unsure of the supported formats in Android, please refer to this page:

http://developer.android.com/guide/appendix/media-formats.html

I think it's possible to do what I want using the MediaPlayer class, but that seems incredibly stupid and inefficient. Also, I'd like a way that's relatively fast.

I'm targeting Android 3.0+, if that makes any difference. Honeycomb also supports .mkv files, although it's not officially supported until Android 4.0.

like image 411
Michell Bak Avatar asked Nov 03 '11 19:11

Michell Bak


People also ask

How can I check the resolution of a video?

To find out video resolution and frame rate of a video file, you can simply view its properties in modern Windows or any other OS. In Windows 7, the information is found out from the Properties > Details (tab) of a video. Video information like frame width and frame height is present there.

How do I know if my video is 720p or 1080p?

Even simpler, you can right-click on the file name in Windows Explorer, select Properties, then look at the Detail tab, you will see the vertical resolution. If it is less than 720, your file is either 720p or 480p, while if it is greater than 720, the file will be at least 1080p.


1 Answers

You can use the MediaMetadataRetriever to retrieve resolution information about a video file. You'd use the extractMetadata() method and using the METADATA_KEY_VIDEO_HEIGHT and METADATA_KEY_VIDEO_WIDTH constants. So you'd do something like this:

MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(/* file descriptor or file path goes here */);
String height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
like image 90
Kurtis Nusbaum Avatar answered Oct 13 '22 01:10

Kurtis Nusbaum