Parsing FLV header (duration) of remote file in Java

点点圈 提交于 2019-12-22 06:24:15

问题


I'm looking for an example of parsing an FLV header for duration specifically in Java. Given the URL of an FLV file I want to download the header only and parse out the duration. I have the FLV spec but I want an example. Python or PHP would be OK too but Java is preferred.


回答1:


Do you have problems downloading the header or parsing it? if it's downloading then use this code:

URL url = new URL(fileUrl);
InputStream dis = url.openStream();
byte[] header = new byte[HEADER_SIZE];
dis.read(header);

You can wrap InputStream with DataInputStream if you want to read int's rather than bytes.

After that just look at getInfo method from PHP-FLV Info or read the spec.




回答2:


As the-alchemist states in this other question:

The Red5 project has a class called FLVReader which does what you want. It's LGPL licensed.

I've tried it and it works fine. You'll need this libraries:

  • Red5 library jar for use when building applications
  • Apache Commons Logging
  • Apache MINA

Getting the FLV video duration is as simple as this:

FLVReader flvReader = new FLVReader(...); // Can use a File or a ByteBuffer as input
long duration = flvReader.getDuration();  // Returns the duration in milliseconds


来源:https://stackoverflow.com/questions/1313640/parsing-flv-header-duration-of-remote-file-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!