Java媒体信息提取器 [英] Media Information Extractor for Java

查看:104
本文介绍了Java媒体信息提取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个可以处理常见媒体格式的媒体信息提取库(纯Java或JNI包装器).我主要将其用于视频文件,并且至少需要以下信息:

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. 视频时长(运行时)
  2. 视频比特率
  3. 视频帧率
  4. 视频格式和编解码器
  5. 视频尺寸(宽X高)
  6. 音频频道
  7. 音频格式
  8. 音频比特率和采样率

周围有几个库和工具,但我找不到Java.

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

推荐答案

问了几天问题后,我发现 MediaInfo ,它提供有关视频或音频文件的许多技术和标签信息.

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.

subs4me

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);

请注意,上面的代码是一个基本示例,不包含任何错误检查(在实际情况下这是一个坏习惯).另请注意,您可以使用MediaInfo提取的信息不仅限于上述信息.请参阅MediaInfo的原始输出,以了解您可以提取或阅读哪种媒体信息 MediaInfo C ++ SDK

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.

这篇关于Java媒体信息提取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆