Posts Tagged ‘tika’

ColdFusion 9: Another Way to Extract FLV Duration

July 29, 2011 5 comments

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","").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: , , ,