Parsing the FLV header (duration) of a remote file in Java

I am looking for an example parsing the FLV header for duration, especially in Java. Given the URL of the FLV file, I want to download only the header and analyze the duration. I have a FLV specification, but I want to give an example. Python or PHP will be fine too, but Java is preferable.

+5
source share
2 answers

Are you having trouble loading the header or parsing it? if it loads, use this code:

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

You can wrap an InputStream with a DataInputStream if you want to read int, not bytes.

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

+1

the-alchemist :

Red5 , FLVReader, , . LGPL.

, . :

FLV :

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

All Articles