rvideo: Ruby video transcoding library

Ruby

  • http://www.ruby-lang.org/en/
    • <<Ruby is…A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.>>
    • Ruby is also totally free. Not only free of charge, but also free to use, copy, modify, and distribute.
    • My MacBook has a copy of it, at [/usr/bin/ruby].  No idea if it came with Mac OS or an application, but it’s there.
  • http://code.google.com/p/rvideo/
    • rvideo
      • Ruby video transcoding library
      • RVideo is a Ruby library inspects and processes video and audio files by providing an interface to free Unix tools like ffmpeg.
    • Demonstration of usage
      • A few examples:
        • file = RVideo::Inspector.new(:file => “#{APP_ROOT}/files/input.mp4”)
        • file = RVideo::Inspector.new(:raw_response => @existing_response)
        • file = RVideo::Inspector.new(:file => “#{APP_ROOT}/files/input.mp4”,
        •   :ffmpeg_binary => “#{APP_ROOT}/bin/ffmpeg”)
        • file.fps        # => “29.97”
        • file.duration   # => “00:05:23.4”
    • To transcode a video, initialize a Transcoder object.
      • transcoder = RVideo::Transcoder.new
    • Then pass a command and valid options to the execute method.
      • recipe = “ffmpeg -i $input_file$ -ar 22050 -ab 64 -f flv -r 29.97 -s”
      • recipe += ” $resolution$ -y $output_file$”
      • recipe += “\nflvtool2 -U $output_file$”
      • begin
      •   transcoder.execute(recipe, {:input_file => “/path/to/input.mp4”,
      •     :output_file => “/path/to/output.flv”, :resolution => “640×360”})
      •   rescue TranscoderError => e
      •   puts “Unable to transcode file: #{e.class} – #{e.message}”
      • end
    • If the job succeeds, you can access the metadata of the input and output files with:
      • transcoder.original     # RVideo::Inspector object
      • transcoder.processed    # RVideo::Inspector object
    • Even if the file is processed, it may still have problems. RVideo will populate an errors array if the duration of the processed video differs from the duration of the original video, or if the processed file is unreadable.

Leave a Reply

You must be logged in to post a comment.