Media Information Extractor for Java

Emre Yazici picture Emre Yazici · Jan 30, 2010 · Viewed 29.6k times · Source

I need a media information extraction library (pure Java or JNI wrapper) that can handle common media formats. I primarily use it for video files and I need at least these information:

  1. Video length (Runtime)
  2. Video bitrate
  3. Video framerate
  4. Video format and codec
  5. Video size (width X height)
  6. Audio channels
  7. Audio format
  8. Audio bitrate and sampling rate

There are several libraries and tools around but I couldn't find for Java.

Answer

Emre Yazici picture Emre Yazici · Aug 19, 2011

After a few days of asking this question, I have found MediaInfo which supplies dozens of technical and tag information about a video or audio file.

There is a JNI wrapper for MediaInfo in subs4me's source tree that I find very useful. Here are some code snippets that show how to extract some information from a media file:

String fileName   = "path/to/my/file";
File file         = new File(fileName);
MediaInfo info    = new MediaInfo();
info.open(file);

String format     = info.get(MediaInfo.StreamKind.Video, i, "Format", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
int bitRate       = info.get(MediaInfo.StreamKind.Video, i, "BitRate", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
float frameRate   = info.get(MediaInfo.StreamKind.Video, i, "FrameRate", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
short width       = info.get(MediaInfo.StreamKind.Video, i, "Width", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);

int audioBitrate  = info.get(MediaInfo.StreamKind.Audio, i, "BitRate", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
int audioChannels = info.get(MediaInfo.StreamKind.Audio, i, "Channels", 
                        MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);

Please note that the above code is a basic example and does not contain any error checking (which is a bad habit in a real scenario). Also note that information that you can extract with MediaInfo does not limited to the ones above. See MediaInfo's raw output to learn which kind of media information you can extract or read MediaInfo C++ SDK.