Class: FFMPEG::Transcoder

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

Constant Summary collapse

@@timeout =
30

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Transcoder.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ffmpeg/transcoder.rb', line 16

def initialize(movie, output_file, options = EncodingOptions.new, transcoder_options = {})
  @movie = movie
  @output_file = output_file

  if options.is_a?(String) || 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 String."
  end

  @transcoder_options = transcoder_options
  @errors = []

  apply_transcoder_options
end

Class Method Details

.timeoutObject



12
13
14
# File 'lib/ffmpeg/transcoder.rb', line 12

def self.timeout
  @@timeout
end

.timeout=(time) ⇒ Object



8
9
10
# File 'lib/ffmpeg/transcoder.rb', line 8

def self.timeout=(time)
  @@timeout = time
end

Instance Method Details

#encodedObject



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

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

#encoding_succeeded?Boolean

Returns:

  • (Boolean)


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

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

#run(&block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ffmpeg/transcoder.rb', line 34

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