java 我如何在java中获取视频长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29984612/
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 get video length in java
提问by Srikanth Shanigaram
I used xuggler to get the video length but it is giving wrong length may be it is time for reading data from video file using xuggler. But i need to get actual video length or duration.
我使用 xuggler 来获取视频长度,但它给出了错误的长度,可能是时候使用 xuggler 从视频文件中读取数据了。但我需要获得实际的视频长度或持续时间。
回答by MaVRoSCy
You can get it with the getDuration()and getFileSize()method of IContainer. You can do it like this:
您可以使用 的getDuration()和getFileSize()方法获取它IContainer。你可以这样做:
private static final String filename = "c:/myvideo.mp4";
IContainer container = IContainer.make();
int result = container.open(filename, IContainer.Type.READ, null);
long duration = container.getDuration();
long fileSize = container.getFileSize();
You can see a complete example here
你可以在这里看到一个完整的例子
Hope this helps
希望这可以帮助

