module FFMPEG

Public Class Methods

ffmpeg_binary() click to toggle source

Get the path to the ffmpeg binary, defaulting to 'ffmpeg'

@return [String] the path to the ffmpeg binary @raise Errno::ENOENT if the ffmpeg binary cannot be found

# File lib/powerand-ffmpeg.rb, line 54
def self.ffmpeg_binary
  @ffmpeg_binary || which('ffmpeg')
end
ffmpeg_binary=(bin) click to toggle source

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 @raise Errno::ENOENT if the ffmpeg binary cannot be found

# File lib/powerand-ffmpeg.rb, line 43
def self.ffmpeg_binary=(bin)
  if bin.is_a?(String) && !File.executable?(bin)
    raise Errno::ENOENT, "the ffmpeg binary, \'#{bin}\', is not executable"
  end
  @ffmpeg_binary = bin
end
ffprobe_binary() click to toggle source

Get the path to the ffprobe binary, defaulting to what is on ENV

@return [String] the path to the ffprobe binary @raise Errno::ENOENT if the ffprobe binary cannot be found

# File lib/powerand-ffmpeg.rb, line 62
def self.ffprobe_binary
  @ffprobe_binary || which('ffprobe')
end
ffprobe_binary=(bin) click to toggle source

Set the path of the ffprobe binary. Can be useful if you need to specify a path such as /usr/local/bin/ffprobe

@param [String] path to the ffprobe binary @return [String] the path you set @raise Errno::ENOENT if the ffprobe binary cannot be found

# File lib/powerand-ffmpeg.rb, line 72
def self.ffprobe_binary=(bin)
  if bin.is_a?(String) && !File.executable?(bin)
    raise Errno::ENOENT, "the ffprobe binary, \'#{bin}\', is not executable"
  end
  @ffprobe_binary = bin
end
logger() click to toggle source

Get FFMPEG logger.

@return [Logger]

# File lib/powerand-ffmpeg.rb, line 30
def self.logger
  return @logger if @logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  @logger = logger
end
logger=(log) click to toggle source

FFMPEG logs information about its progress when it's transcoding. Jack in your own logger through this method if you wish to.

@param [Logger] log your own logger @return [Logger] the logger you set

# File lib/powerand-ffmpeg.rb, line 23
def self.logger=(log)
  @logger = log
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH.

which('ruby') #=> /usr/bin/ruby

see: stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby

# File lib/powerand-ffmpeg.rb, line 83
def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable? exe
    }
  end
  raise Errno::ENOENT, "the #{cmd} binary could not be found in #{ENV['PATH']}"
end