Module: FFMPEG

Defined in:
lib/ffmpeg/movie.rb,
lib/ffmpeg/errors.rb,
lib/ffmpeg/version.rb,
lib/streamio-ffmpeg.rb,
lib/ffmpeg/transcoder.rb,
lib/ffmpeg/encoding_options.rb

Defined Under Namespace

Classes: EncodingOptions, Error, Movie, Transcoder

Constant Summary collapse

VERSION =
'3.0.0'

Class Method Summary collapse

Class Method Details

.ffmpeg_binaryString

Get the path to the ffmpeg binary, defaulting to ‘ffmpeg’

Returns:

  • (String)

    the path to the ffmpeg binary

Raises:

  • Errno::ENOENT if the ffmpeg binary cannot be found



50
51
52
# File 'lib/streamio-ffmpeg.rb', line 50

def self.ffmpeg_binary
  @ffmpeg_binary || which('ffmpeg')
end

.ffmpeg_binary=(bin) ⇒ String

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

Parameters:

  • path (String)

    to the ffmpeg binary

Returns:

  • (String)

    the path you set

Raises:

  • Errno::ENOENT if the ffmpeg binary cannot be found



39
40
41
42
43
44
# File 'lib/streamio-ffmpeg.rb', line 39

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_binaryString

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

Returns:

  • (String)

    the path to the ffprobe binary

Raises:

  • Errno::ENOENT if the ffprobe binary cannot be found



58
59
60
# File 'lib/streamio-ffmpeg.rb', line 58

def self.ffprobe_binary
  @ffprobe_binary || which('ffprobe')
end

.ffprobe_binary=(bin) ⇒ String

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

Parameters:

  • path (String)

    to the ffprobe binary

Returns:

  • (String)

    the path you set

Raises:

  • Errno::ENOENT if the ffprobe binary cannot be found



68
69
70
71
72
73
# File 'lib/streamio-ffmpeg.rb', line 68

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

.loggerLogger

Get FFMPEG logger.

Returns:

  • (Logger)


26
27
28
29
30
31
# File 'lib/streamio-ffmpeg.rb', line 26

def self.logger
  return @logger if @logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  @logger = logger
end

.logger=(log) ⇒ Logger

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

Parameters:

  • log (Logger)

    your own logger

Returns:

  • (Logger)

    the logger you set



19
20
21
# File 'lib/streamio-ffmpeg.rb', line 19

def self.logger=(log)
  @logger = log
end

.which(cmd) ⇒ Object

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

Raises:

  • (Errno::ENOENT)


79
80
81
82
83
84
85
86
87
88
# File 'lib/streamio-ffmpeg.rb', line 79

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