Class: FFMPEG::Transcoder

Inherits:
Object
  • Object
show all
Defined in:
lib/ffmpeg/transcoder.rb

Constant Summary collapse

@@timeout =
30

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output_file, options = EncodingOptions.new, transcoder_options = {}) ⇒ Transcoder


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ffmpeg/transcoder.rb', line 13

def initialize(input, output_file, options = EncodingOptions.new, transcoder_options = {})
  if input.is_a?(FFMPEG::Movie)
    @movie = input
    @input = input.path
  end
  @output_file = output_file

  @raw_options, @transcoder_options = optimize_screenshot_parameters(options, transcoder_options)

  @errors = []

  apply_transcoder_options

  @input = @transcoder_options[:input] unless @transcoder_options[:input].nil?

  input_options = @transcoder_options[:input_options] || []
  iopts = []

  if input_options.is_a?(Array)
    iopts += input_options
  else
    input_options.each { |k, v| iopts += ['-' + k.to_s, v] }
  end

  @command = [FFMPEG.ffmpeg_binary, '-y', *iopts, '-i', @input, *@raw_options.to_a, @output_file]
end

Class Attribute Details

.timeoutObject

Returns the value of attribute timeout


10
11
12
# File 'lib/ffmpeg/transcoder.rb', line 10

def timeout
  @timeout
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command


5
6
7
# File 'lib/ffmpeg/transcoder.rb', line 5

def command
  @command
end

#inputObject (readonly)

Returns the value of attribute input


5
6
7
# File 'lib/ffmpeg/transcoder.rb', line 5

def input
  @input
end

Instance Method Details

#encodedObject


54
55
56
# File 'lib/ffmpeg/transcoder.rb', line 54

def encoded
  @encoded ||= Movie.new(@output_file) if File.exist?(@output_file)
end

#encoding_succeeded?Boolean


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

def encoding_succeeded?
  @errors.empty?
end

#run(&block) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'lib/ffmpeg/transcoder.rb', line 40

def run(&block)
  transcode_movie(&block)
  if @transcoder_options[:validate]
    validate_output_file(&block)
    return encoded
  else
    return nil
  end
end

#timeoutObject


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

def timeout
  self.class.timeout
end