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 。
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.
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.
发布评论
评论(4)
问这个问题几天后,我发现 MediaInfo 它提供了有关视频或视频的数十个技术和标签信息音频文件。
subs4me 的 源代码树
我觉得非常有用。以下是一些代码片段,展示了如何从媒体文件中提取一些信息:
请注意,上面的代码是一个基本示例,不包含任何错误检查(这在实际场景中是一个坏习惯)。另请注意,您可以使用 MediaInfo 提取的信息并不限于上述信息。请参阅 MediaInfo 的原始输出,了解您可以提取或读取哪种媒体信息MediaInfo C++ SDK 。
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:
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.
你不需要这个东西的框架,例如 AVI 视频容器格式有一个 56 字节标头 包含所有相关元数据。 该网站上还有很多其他格式,所有这些似乎都很琐碎来实施。
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.
尝试 Xuggler。以下是一些 Xuggler 源代码查询媒体文件并打印出各种有用的元数据的代码。
Try Xuggler. Here's some Xuggler source code that queries a media file and prints out all sorts of useful meta-data.
您是否尝试过 Java Media Framework API http://java.sun.com/ javase/technologies/desktop/media/jmf/ 但我不确定它是否会有足够的支持,就像上面使用 FFMpeg 的 Xuggle 一样,使用它的唯一优点是跨平台支持。
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.