Skip to content

Commit

Permalink
Merge pull request streamio#10 from jonathandean/master
Browse files Browse the repository at this point in the history
Added ability to specify the path to the ffmpeg binary.
  • Loading branch information
dbackeus committed Aug 19, 2011
2 parents 2eb6f8e + 351b9bd commit 660d564
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.rdoc
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion lib/ffmpeg/movie.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/ffmpeg/transcoder.rb
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions lib/streamio-ffmpeg.rb
Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/streamio-ffmpeg_spec.rb
Expand Up @@ -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.