1. Skip to navigation
  2. Skip to content

The ELC Community Blog

A knowledge exchange on Ruby on Rails and Agile Development


Transcoding with On2 and Ruby

by Dylan Stamat on October 27, 2007

The FlixEngine by On2 has a great API. The only problem was that there were no Ruby bindings for it, that is, until a few months ago. Matt Bauer of MMMultiworks started a great Ruby implementation off of it's C API. I recommend reading Matt's post about it, as he explains about the engine and its implementation in some good detail:
http://blog.mmmultiworks.com/2007/5/18/on2-flix-engine

On a recent project, I had the opportunity to use his bindings, and ended up implementing some other chunks of the FlixEngine API. The patches is quite big, and I hope to be adding it to the RubyForge project soon. Here is a small example that illustrates how easy it is to interface with FlixEngine though the Ruby API:

   1  <pre>
   2    # load the file
   3    flix_engine = On2::FlixEngine.new(localhost, 0)
   4    flix_engine.source_path = "my_video.mpg"
   5    flix_engine.output_path = "my_video.flv"
   6  
   7    # set video scaling parameters
   8    flix_engine.scale({
   9      :height => 250,
  10      :width  => 250
  11    })      
  12  
  13    # set exported PNG scaling parameters
  14    flix_engine.png({
  15      :height  => 250,
  16      :width  => 250,
  17      :export_time  => "10000",
  18      :prefix  => "my_video",
  19      :suffix  => "video_thumb" 
  20    })      
  21    
  22    flix_engine.state  # queued
  23  
  24    # start encoding
  25    duration = Benchmark.realtime {
  26      flix_engine.encode
  27      while (flix_engine.encoding?)
  28        flix_engine.state  # running
  29        sleep 1 
  30      end     
  31    }
  32  
  33    flix_engine.success?  # boolean status
  34    flix_engine.duration  # the duration of the outputted video
  35    flix_engine.flix_error  # flix engine errors
  36    flix_engine.system_error  # system specific errors
  37  </pre>

There are quite a few other API calls that you can utilize as well. If you use On2's FlixEngine, and have any other additions/questions, please let Matt or I know !

Note that a bunch of the calls in the example are not in trunk at the moment, and if you need them now, let me know.

Happy transcoding !

Comments

Confused at 9:43 PM on October 28 2007

Is there a lynx plugin for this??

Add a comment


home | services | Ruby on Rails Development | code | blog | company