diff --git a/README.rdoc b/README.rdoc index 7a7d14af..d45c0c57 100644 --- a/README.rdoc +++ b/README.rdoc @@ -94,6 +94,14 @@ Use ffpreset files to avoid headaches when encoding with libx264 (http://www.ffm options = {:video_codec => "libx264", :video_preset => "medium"} # audio_preset and file_preset also availible movie.transcode("movie.mp4", options) # encodes video using libx264-medium.ffpreset +== Specify the path to ffmpeg + +By default, streamio assumes that the ffmpeg binary is available in the execution path and named ffmpeg and so will run commands that look something like "ffmpeg -i /path/to/input.file ...". Use the FFMPEG.ffmpeg_binary setter to specify the full path to the binary if necessary: + + FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg' + +This will cause the same command to run as "/usr/local/bin/ffmpeg -i /path/to/input.file ..." instead. + == Copyright Copyright (c) 2010 Streamio Networks AB. See LICENSE for details. diff --git a/lib/ffmpeg/movie.rb b/lib/ffmpeg/movie.rb index bc2a7f7f..061e5a56 100644 --- a/lib/ffmpeg/movie.rb +++ b/lib/ffmpeg/movie.rb @@ -9,7 +9,7 @@ def initialize(path) @path = escape(path) - stdin, stdout, stderr = Open3.popen3("ffmpeg -i '#{path}'") # Output will land in stderr + stdin, stdout, stderr = Open3.popen3("#{FFMPEG.ffmpeg_binary} -i '#{path}'") # Output will land in stderr output = stderr.read fix_encoding(output) diff --git a/lib/ffmpeg/transcoder.rb b/lib/ffmpeg/transcoder.rb index 28aed621..89d5e1e0 100644 --- a/lib/ffmpeg/transcoder.rb +++ b/lib/ffmpeg/transcoder.rb @@ -23,7 +23,7 @@ def initialize(movie, output_file, options = EncodingOptions.new, transcoder_opt # ffmpeg < 0.8: frame= 413 fps= 48 q=31.0 size= 2139kB time=16.52 bitrate=1060.6kbits/s # ffmpeg >= 0.8: frame= 4855 fps= 46 q=31.0 size= 45306kB time=00:02:42.28 bitrate=2287.0kbits/ def run - command = "ffmpeg -y -i '#{@movie.path}' #{@raw_options} '#{@output_file}'" + command = "#{FFMPEG.ffmpeg_binary} -y -i '#{@movie.path}' #{@raw_options} '#{@output_file}'" FFMPEG.logger.info("Running transcoding...\n#{command}\n") output = "" last_output = nil diff --git a/lib/streamio-ffmpeg.rb b/lib/streamio-ffmpeg.rb index 7084e464..1892c5b7 100644 --- a/lib/streamio-ffmpeg.rb +++ b/lib/streamio-ffmpeg.rb @@ -27,4 +27,20 @@ def self.logger logger.level = Logger::INFO @logger = logger end + + # Set the path of the ffmpeg binary. + # Can be useful if you need to specify a path such as /usr/local/bin/ffmpeg + # + # @param [String] path to the ffmpeg binary + # @return [String] the path you set + def self.ffmpeg_binary=(bin) + @ffmpeg_binary = bin + end + + # Get the path to the ffmpeg binary, defaulting to 'ffmpeg' + # + # @return [String] the path to the ffmpeg binary + def self.ffmpeg_binary + @ffmpeg_binary.nil? ? 'ffmpeg' : @ffmpeg_binary + end end diff --git a/spec/streamio-ffmpeg_spec.rb b/spec/streamio-ffmpeg_spec.rb index 2e423d50..86b65a6e 100644 --- a/spec/streamio-ffmpeg_spec.rb +++ b/spec/streamio-ffmpeg_spec.rb @@ -21,4 +21,20 @@ FFMPEG.logger.should == new_logger end end + + describe "ffmpeg_binary" do + after(:each) do + FFMPEG.ffmpeg_binary = nil + end + + it "should default to 'ffmpeg'" do + FFMPEG.ffmpeg_binary.should == 'ffmpeg' + end + + it "should be assignable" do + new_binary = '/usr/local/bin/ffmpeg' + FFMPEG.ffmpeg_binary = new_binary + FFMPEG.ffmpeg_binary.should == new_binary + end + end end \ No newline at end of file