开发者

Media Information Extractor for Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 8 years ago.

开发者_开发知识库 Improve this 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜