Permalink
Browse files

Merge pull request #10 from jonathandean/master

Added ability to specify the path to the ffmpeg binary.
  • Loading branch information...
2 parents 2eb6f8e + 351b9bd commit 660d5641c637b167463c927ead0faf9f052fcff8 @dbackeus dbackeus committed Aug 19, 2011
Showing with 42 additions and 2 deletions.
  1. +8 −0 README.rdoc
  2. +1 −1 lib/ffmpeg/movie.rb
  3. +1 −1 lib/ffmpeg/transcoder.rb
  4. +16 −0 lib/streamio-ffmpeg.rb
  5. +16 −0 spec/streamio-ffmpeg_spec.rb
View
8 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.
View
2 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)
View
2 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
View
16 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
View
16 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

0 comments on commit 660d564

Please sign in to comment.