java 如何从各种视频文件格式中提取元数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4941961/
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
How can I extract meta data from various video file formats?
提问by jens
How can I extract meta data from various video file formats, especially the Resolution and the type of codec used. (But also all other stuff like author). I was not able to find a library for that.
如何从各种视频文件格式中提取元数据,尤其是分辨率和使用的编解码器类型。(但还有像作者这样的所有其他东西)。我无法为此找到图书馆。
回答by vikiiii
I have found MediaInfo, which 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.
在subs4me 的源代码树中有一个 MediaInfo 的 JNI 包装器,我发现它非常有用。
Here are some code snippets that show how to extract some information from a media file:
以下是一些代码片段,展示了如何从媒体文件中提取一些信息:
File file = new File("path/to/my/file");
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);
回答by Cédrick Lunven
The vikiiiisolutions works, but I found :
该vikiiii解决方案的作品,但我发现:
- It still required a bit of work to get everything running on my desktop. (download the dll, extract the code, browse files...)
- We have no clue of the constants (like "BitRate") available
- 仍然需要做一些工作才能在我的桌面上运行所有内容。(下载dll,解压代码,浏览文件...)
- 我们不知道可用的常量(如“BitRate”)
As a consequence I installed the Windows MediaInfo application and search which are the Keys available to create some java Enum and ease usage.
因此,我安装了 Windows MediaInfo 应用程序并搜索了可用于创建一些 java Enum 并简化使用的密钥。
I created a repository on github https://github.com/clun/movies-metadatato have everything in the same place. Just run mvn:test
on the sample project to get informations on samples MP4, OGG, AVI, FLV, WEBM and MKV.
我在 github https://github.com/clun/movies-metadata上创建了一个存储库,将所有内容都放在同一个地方。只需运行mvn:test
示例项目即可获取有关示例 MP4、OGG、AVI、FLV、WEBM 和 MKV 的信息。
Here the sample code of the test :
这里是测试的示例代码:
MovieMetadata movieMedataData = new MovieMetadata("./src/test/resources/small.mkv");
movieMedataData.get(General.FORMAT);
movieMedataData.get(Video.DURATION_STRING);
movieMedataData.get(Video.WIDTH_STRING);
movieMedataData.get(Video.HEIGHT_STRING);
movieMedataData.get(Video.BITRATE_STRING);
movieMedataData.get(Audio.COMPRESSION_RATIO);
//...