如何在ruby项目中包含库?

时间:2013-01-09 10:02:57

标签: ruby ffmpeg video-streaming jruby

我安装了rvideo

gem install rvideo
aptitude install ffmpeg

我在阅读手册时使用rvideo写了以下内容。

#!/usr/bin/env ruby

file = RVideo::Inspector.new(:file => "/home/user/r/input.mp4")
file.fps        # => "29.97" 
file.duration   # => "00:40:23.4" 

transcoder = RVideo::Transcoder.new

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 => "/home/user/r/input.mp4",
:output_file => "/home/user/r/output.flv", :resolution => "640x360"})
rescue TranscoderError => e
puts "Unable to transcode file: #{e.class} - #{e.message}"
end

transcoder.original     # RVideo::Inspector object
transcoder.processed    # RVideo::Inspector object

当我这样做时:

$ ruby hw.rb

我明白了:

first.rb:3: uninitialized constant RVideo (NameError)

在手册中,我找到了这段代码:

require 'test/unit/assertions'
include Test::Unit::Assertions
puts assert_equal nil == nil, nil.nil?

如何在我的案例中包含rvideo库?我如何知道图书馆的路径?

1 个答案:

答案 0 :(得分:2)

#!/usr/bin/env ruby

require 'rubygems'
require 'rvideo'

file = RVideo::Inspector.new(:file => "/home/user/r/input.mp4")
file.fps        # => "29.97" 
file.duration   # => "00:40:23.4" 

# rest of the code follows