Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

The FileBot source contains original and best maintained MediaInfo JNA wrapper:

https://github.com/filebot/filebot/blob/master/source/net/filebot/mediainfo/MediaInfo.java

I've been using the MediaInfo native libs in my OSS FileBot for more than 2 years. Works very well on all platforms. Windows, Linux, MacOS and even Embedded Linux (ARM).

http://www.filebot.net/

You don't need a framework for this stuff, for example AVI video container format has a 56 byte header containing all the relevant metadata. There's bunch of other formats on that site too, all of them seem to be quite trivial to implement.

Try Xuggler. Here's some Xuggler source code that queries a media file and prints out all sorts of useful meta-data.

  • Art

Have you tried Java Media Framework API http://java.sun.com/javase/technologies/desktop/media/jmf/ but I am not sure if it will have enough support as Xuggle above which uses FFMpeg, the only advantage of using this would be cross platform support.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top