From 56d5306c2c7dc449f188101ff31441c951acc148 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sun, 21 Dec 2014 21:28:37 +0100 Subject: [PATCH] Try to find the ffmpeg binary automatically --- lib/streamio-ffmpeg.rb | 21 +++++++++++++++++++-- spec/streamio-ffmpeg_spec.rb | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/streamio-ffmpeg.rb b/lib/streamio-ffmpeg.rb index 4e00df99..c29d7319 100644 --- a/lib/streamio-ffmpeg.rb +++ b/lib/streamio-ffmpeg.rb @@ -39,10 +39,27 @@ def self.ffmpeg_binary=(bin) @ffmpeg_binary = bin end - # Get the path to the ffmpeg binary, defaulting to 'ffmpeg' + # Get the path to the ffmpeg binary # # @return [String] the path to the ffmpeg binary def self.ffmpeg_binary - @ffmpeg_binary || 'ffmpeg' + @ffmpeg_binary ||= find_ffmpeg_binary end + + # Tries find the ffmpeg binary + # + # @return [String] the path to the ffmpeg binary + def self.find_ffmpeg_binary + %w( + /usr/bin/avconv + /usr/bin/ffmpeg + /usr/local/bin/avconv + /usr/local/bin/ffmpeg + ).each do |path| + return path if File.exists?(path) + end + + raise "unable to find ffmpeg binary" + end + end diff --git a/spec/streamio-ffmpeg_spec.rb b/spec/streamio-ffmpeg_spec.rb index 86b65a6e..91c77c1b 100644 --- a/spec/streamio-ffmpeg_spec.rb +++ b/spec/streamio-ffmpeg_spec.rb @@ -27,8 +27,9 @@ FFMPEG.ffmpeg_binary = nil end - it "should default to 'ffmpeg'" do - FFMPEG.ffmpeg_binary.should == 'ffmpeg' + it "should default to 'avconv'" do + File.stub(:exists?){ true } + FFMPEG.ffmpeg_binary.should == '/usr/bin/avconv' end it "should be assignable" do