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

Returns a new instance of 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
39
40
# 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

  if options.is_a?(Array) || options.is_a?(EncodingOptions)
    @raw_options = options
  elsif options.is_a?(Hash)
    @raw_options = EncodingOptions.new(options)
  else
    raise ArgumentError, "Unknown options format '#{options.class}', should be either EncodingOptions, Hash or Array."
  end

  @transcoder_options = transcoder_options
  @errors = []

  apply_transcoder_options

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

  input_options = @transcoder_options[:input_options] || []
  iopts = []
  input_options.each { |k, v| iopts += ['-' + k.to_s, v] }

  @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



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

def encoded
  @encoded ||= Movie.new(@output_file)
end

#encoding_succeeded?Boolean

Returns:

  • (Boolean)


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

def encoding_succeeded?
  @errors << "no output file created" and return false unless File.exist?(@output_file)
  @errors << "encoded file is invalid" and return false unless encoded.valid?
  true
end

#run(&block) ⇒ Object



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

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

#timeoutObject



62
63
64
# File 'lib/ffmpeg/transcoder.rb', line 62

def timeout
  self.class.timeout
end