Skip to content

Commit 56d5306

Browse files
committed
Try to find the ffmpeg binary automatically
1 parent 1a7db76 commit 56d5306

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/streamio-ffmpeg.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,27 @@ def self.ffmpeg_binary=(bin)
3939
@ffmpeg_binary = bin
4040
end
4141

42-
# Get the path to the ffmpeg binary, defaulting to 'ffmpeg'
42+
# Get the path to the ffmpeg binary
4343
#
4444
# @return [String] the path to the ffmpeg binary
4545
def self.ffmpeg_binary
46-
@ffmpeg_binary || 'ffmpeg'
46+
@ffmpeg_binary ||= find_ffmpeg_binary
4747
end
48+
49+
# Tries find the ffmpeg binary
50+
#
51+
# @return [String] the path to the ffmpeg binary
52+
def self.find_ffmpeg_binary
53+
%w(
54+
/usr/bin/avconv
55+
/usr/bin/ffmpeg
56+
/usr/local/bin/avconv
57+
/usr/local/bin/ffmpeg
58+
).each do |path|
59+
return path if File.exists?(path)
60+
end
61+
62+
raise "unable to find ffmpeg binary"
63+
end
64+
4865
end

spec/streamio-ffmpeg_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
FFMPEG.ffmpeg_binary = nil
2828
end
2929

30-
it "should default to 'ffmpeg'" do
31-
FFMPEG.ffmpeg_binary.should == 'ffmpeg'
30+
it "should default to 'avconv'" do
31+
File.stub(:exists?){ true }
32+
FFMPEG.ffmpeg_binary.should == '/usr/bin/avconv'
3233
end
3334

3435
it "should be assignable" do

0 commit comments

Comments
 (0)