Home > ColdFusion, Java > ColdFusion 9: Another Way to Extract FLV Duration

ColdFusion 9: Another Way to Extract FLV Duration

I saw an interesting question this week about using Tika with Railo.   If you are like me, and know very little about Tika,  it is described as a library that

    … detects and extracts metadata and structured text content from various documents..

Now despite knowing very little about it, I was pretty sure it was included in ColdFusion 9 (with its  Solr integration).  I took a look around and sure enough ColdFusion 9 includes a slightly older version of Tika (0.6) under the hood.

While reviewing the API I noticed it mentioned a simple FLVParser.  Interesting.  So I decided to give it a whirl.  First I created an instance of Metadata to store the details retrieved from my test file.  Next I loaded my sample file as an input stream.  Finally, I ran the objects through the Tika parser to actually populate the metadata.  Then with a simple call to Metadata.get() I had the file’s duration.

    path   = "c:/myFile.flv";
    Tika   = createObject("java", "org.apache.tika.Tika");
    meta   = createObject("java", "org.apache.tika.metadata.Metadata").init();
    stream = createObject("java","java.io.FileInputStream").init( path );

    try {
        Tika.parse(stream, meta);
        WriteOutput("<p>duration="& meta.get("duration") &"</p>");
        // ....
    finally {

The parser also extracts a few other interesting details like framerate, width, height and a few others. To review all of the properties found,  just invoke MetaData.names() . Then iterate through the array of property names returned.  Keep in mind this class is just a simple parser. But no extra jars are required to use it!

    // get all properties names returned
    names = meta.names();
    for (i = 1; i <= arrayLen(names); i++) {
       key = names[i];
       writeOutput("<p>"& key &"="& meta.get( javacast("string", key)) &"</p>");
Categories: ColdFusion, Java Tags: , , ,
  1. Rhys Jones
    March 12, 2012 at 8:09 am

    Hello, I read this post above with interest as we are trying to extend Solr’s abilities beyond what cfindex & cfsearch expose. I’ve gotten as far as understanding how to get beyond the custom fields and actually index a query in a more natural way (with fieldnames, etc). What I haven’t been able to figure out, and it looks like you did, was how cfindex is indexing documents…apparently by using Tika… I was wondering how you went about finding the tika installation. I wanted to see what version I’m running of it…

  2. Rhys Jones
    March 12, 2012 at 8:27 am

    Nevermind…found the tika libs…appreciate your post at least jump-starting my research.

  3. Rhys Jones
    March 14, 2012 at 6:30 am

    While I can utilize your implementation of tika.parse(), passing the filestream object and the meta, when I go to try and actually get at the parsed content, (parsing a PDF), the method fails when I try to pass all 4 parameters to the method. Any thoughts?

  4. ramen
    September 7, 2012 at 3:11 am

    is it possible to overwrite this version of tika (0.6) with 1.2? thanks

  5. September 7, 2012 at 2:11 pm

    @ramen – I believe so. But as it is used by CF, you would have do some testing to make sure upgrading did not break anything.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: