flash duration

Is there a way in Rails to get the duration (minutes, seconds, etc.) of a flash video? I want to display the amount of time to the users before they start playing it or downloading it.

I control the flash video and it is in my public directory.

There are many video clips and they change frequently and I don't want to have to look at them and store the length when I copy the file over.

Do you know a way of determining the time via command line?


Saturday, March 19, 2011, 11:12:58 AM, you wrote:

The mediainfo CLI app, or ffmpeg if that doesn't work. You can shell out to the CLI with the back-tick operator, and the return from either of these will be plain text, suitable for further regular-expression-bashing.


For those who may need the answer to this question I will outline my OS-independent solution.

The file format of an .flv file is documented in

To spare you the effort of reading the documentation ...

Read the metadata header into a string. Reading 10K should be way more than enough.

Search for the string "duration" (without the quotes). "duration" is null terminated.

The next 16 bytes are a double and can be interpreted as String.unpack("G").

The double so interpreted is the duration in seconds.

Have you checked the flvtool2 gem to see if that gets you what you need ?