是否有用于提取 MP4 元数据的 JAVA API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12679662/
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
Is there a JAVA API for extract MP4 Metadata
提问by Churk
I want to be specific as to what I am asking. I am not asking to modified any MP4 files, just extract metadata such as Width and Height and bitrate and encoding and this is not in the MP3 tags.
我想具体说明我在问什么。我不要求修改任何 MP4 文件,只是提取元数据,例如宽度和高度以及比特率和编码,这不在 MP3 标签中。
I have tested Xuggle which works, but I need to have a library that does not use JNI or any native code.
我已经测试了 Xuggle 的工作原理,但我需要一个不使用 JNI 或任何本机代码的库。
I already looked into MP4Parser, and Apache Tika, and they both does not extract metadata, just tag info or alter the file.
我已经研究过 MP4Parser 和 Apache Tika,它们都不提取元数据,只是标记信息或更改文件。
Is there such java lib?
有这样的java lib吗?
回答by Churk
I actually found what I was looking for using Mp4Parser
here is a simple lines of code to get what I wanted using Mp4Parser
这是使用 Mp4Parser 获得我想要的简单代码行
FileChannel fc = new FileInputStream("content/Video_720p_Madagascar-3.mp4").getChannel();
IsoFile isoFile = new IsoFile(fc);
MovieBox moov = isoFile.getMovieBox();
for(Box b : moov.getBoxes()) {
System.out.println(b);
}
b contains all the info I needed, now I just have to parse b to get exactly what I want.
b 包含我需要的所有信息,现在我只需要解析 b 即可获得我想要的信息。
回答by Kirill Feoktistov
At present (2015), Android SDK provides MediaMetadataRetrieverclass for extracting metadata:
目前(2015年)Android SDK提供了用于提取元数据的MediaMetadataRetriever类:
MediaMetadataRetriever m = new MediaMetadataRetriever();
m.setDataSource(mInputFile);
String extractedHeight = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String extractedWidth = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);