Java 媒体信息提取器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2168472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Media Information Extractor for Java
提问by Emre Yazici
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:
我需要一个可以处理常见媒体格式的媒体信息提取库(纯 Java 或 JNI 包装器)。我主要将它用于视频文件,我至少需要以下信息:
- Video length (Runtime)
- Video bitrate
- Video framerate
- Video format and codec
- Video size (width X height)
- Audio channels
- Audio format
- Audio bitrate and sampling rate
- 视频长度(运行时)
- 视频比特率
- 视频帧率
- 视频格式和编解码器
- 视频尺寸(宽 X 高)
- 音频通道
- 音频格式
- 音频比特率和采样率
There are several libraries and tools around but I couldn't find for Java.
周围有几个库和工具,但我找不到用于 Java 的库和工具。
采纳答案by Emre Yazici
After a few days of asking this question, I have found MediaInfowhich supplies dozens of technical and tag information about a video or audio file.
在问这个问题几天后,我发现MediaInfo提供了许多关于视频或音频文件的技术和标签信息。
There is a JNI wrapper for MediaInfo in subs4me's source treethat I find very useful. Here are some code snippets that show how to extract some information from a media file:
在subs4me的源代码树中有一个 MediaInfo 的 JNI 包装器,我发现它非常有用。以下是一些代码片段,展示了如何从媒体文件中提取一些信息:
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.
请注意,上面的代码是一个基本示例,不包含任何错误检查(这在实际场景中是一个坏习惯)。另请注意,您可以使用 MediaInfo 提取的信息不限于上述信息。请参阅 MediaInfo 的原始输出以了解您可以提取或读取MediaInfo C++ SDK的媒体信息类型。
回答by Esko
You don't need a framework for this stuff, for example AVI video container format has a 56 byte headercontaining all the relevant metadata. There's bunch of other formats on that site too, all of them seem to be quite trivial to implement.
你不需要这些东西的框架,例如 AVI 视频容器格式有一个56 字节的标头,包含所有相关的元数据。该站点上还有许多其他格式,所有这些格式似乎都很难实现。
回答by Art Clarke
Try Xuggler. Here's some Xuggler source codethat queries a media file and prints out all sorts of useful meta-data.
试试Xuggler。这是一些查询媒体文件并打印出各种有用元数据的 Xuggler源代码。
- Art
- 艺术
回答by Archimedes Trajano
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.
您是否尝试过 Java 媒体框架 API http://java.sun.com/javase/technologies/desktop/media/jmf/但我不确定它是否会像上面使用 FFMpeg 的 Xuggle 一样有足够的支持,这是使用的唯一优势这将是跨平台支持。
回答by rednoah
The FileBot source contains original and best maintained MediaInfo JNA wrapper:
FileBot 源包含原始且维护良好的 MediaInfo JNA 包装器:
https://github.com/filebot/filebot/blob/master/source/net/filebot/mediainfo/MediaInfo.java
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).
我在我的 OSS FileBot 中使用 MediaInfo 原生库已经超过 2 年了。在所有平台上都能很好地工作。Windows、Linux、MacOS 甚至嵌入式 Linux (ARM)。