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, HTTPTooManyRequests, Movie, Transcoder

Constant Summary collapse

VERSION =
'3.0.2'

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

.max_http_redirect_attemptsInteger

Get the maximum number of http redirect attempts

Returns:

  • (Integer)

    the maximum number of retries



78
79
80
# File 'lib/streamio-ffmpeg.rb', line 78

def self.max_http_redirect_attempts
  @max_http_redirect_attempts.nil? ? 10 : @max_http_redirect_attempts
end

.max_http_redirect_attempts=(v) ⇒ Integer

Set the maximum number of http redirect attempts.

Parameters:

  • the (Integer)

    maximum number of retries

Returns:

  • (Integer)

    the number of retries you set

Raises:

  • Errno::ENOENT if the value is negative or not an Integer



87
88
89
90
91
# File 'lib/streamio-ffmpeg.rb', line 87

def self.max_http_redirect_attempts=(v)
  raise Errno::ENOENT, 'max_http_redirect_attempts must be an integer' if v && !v.is_a?(Integer)
  raise Errno::ENOENT, 'max_http_redirect_attempts may not be negative' if v && v < 0
  @max_http_redirect_attempts = v
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)


97
98
99
100
101
102
103
104
105
106
# File 'lib/streamio-ffmpeg.rb', line 97

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