Class: VideoConverter::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/video_converter/output.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Output

Returns a new instance of Output.

Raises:

  • (ArgumentError)


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
41
42
43
44
# File 'lib/video_converter/output.rb', line 15

def initialize params = {}
  self.work_dir = File.join(self.class.work_dir, params[:uid])
  self.mkdir_mode = params[:mkdir_mode]
  self.mkdir_mode = mkdir_mode.to_i(8) if mkdir_mode.is_a?(String)
  FileUtils.mkdir_p(work_dir, :mode => mkdir_mode)
  self.filename = params[:filename] or raise ArgumentError.new('Filename required')
  self.log = File.join(work_dir, self.class.log)
  self.type = params[:type] || 'default'
  if type == 'segmented'
    self.chunks_dir = File.join(work_dir, File.basename(filename, '.*'))
    FileUtils.mkdir_p(chunks_dir, :mode => mkdir_mode)
    if File.extname(filename) == '.m3u8'
      self.ffmpeg_output = chunks_dir + '.ts'
      params[:format] = 'mpegts'
    elsif File.extname(filename) == '.f4m'
      self.ffmpeg_output = chunks_dir = '.mp4'
      params[:format] = 'mp4'
    else
      raise "Invalid filename for type segmented"
    end
  else
    self.ffmpeg_output = File.join(work_dir, filename)
  end
  raise ArgumentError.new('Invalid type') unless %w(default segmented playlist).include?(type)
  [:path, :streams, :width, :height, :one_pass, :rotate, :faststart, :thumbnails, :group, :drm, :no_fragments, :crop, :watermarks, :volume, :encryption_key, :encryption_key_url].each { |attr| self.send("#{attr}=", params[attr]) }
  [:video_bitrate, :audio_bitrate].each { |bitrate| params[bitrate] = "#{params[bitrate]}k" if params[bitrate].is_a?(Numeric) }

  # options will be substituted to convertation commands
  self.options = params
end

Class Attribute Details

.keyframe_interval_in_secondsObject

Returns the value of attribute keyframe_interval_in_seconds.



6
7
8
# File 'lib/video_converter/output.rb', line 6

def keyframe_interval_in_seconds
  @keyframe_interval_in_seconds
end

.logObject

Returns the value of attribute log.



6
7
8
# File 'lib/video_converter/output.rb', line 6

def log
  @log
end

.work_dirObject

Returns the value of attribute work_dir.



6
7
8
# File 'lib/video_converter/output.rb', line 6

def work_dir
  @work_dir
end

Instance Attribute Details

#chunks_dirObject

Returns the value of attribute chunks_dir.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def chunks_dir
  @chunks_dir
end

#cropObject

Returns the value of attribute crop.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def crop
  @crop
end

#drmObject

Returns the value of attribute drm.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def drm
  @drm
end

#encryption_keyObject

Returns the value of attribute encryption_key.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def encryption_key
  @encryption_key
end

#encryption_key_urlObject

Returns the value of attribute encryption_key_url.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def encryption_key_url
  @encryption_key_url
end

#faststartObject

Returns the value of attribute faststart.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def faststart
  @faststart
end

#ffmpeg_outputObject

Returns the value of attribute ffmpeg_output.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def ffmpeg_output
  @ffmpeg_output
end

#filenameObject

Returns the value of attribute filename.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def filename
  @filename
end

#groupObject

Returns the value of attribute group.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def group
  @group
end

#heightObject

Returns the value of attribute height.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def height
  @height
end

#logObject

Returns the value of attribute log.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def log
  @log
end

#mkdir_modeObject

Returns the value of attribute mkdir_mode.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def mkdir_mode
  @mkdir_mode
end

#no_fragmentsObject

Returns the value of attribute no_fragments.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def no_fragments
  @no_fragments
end

#one_passObject

Returns the value of attribute one_pass.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def one_pass
  @one_pass
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def options
  @options
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def path
  @path
end

#rotateObject

Returns the value of attribute rotate.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def rotate
  @rotate
end

#streamsObject

Returns the value of attribute streams.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def streams
  @streams
end

#thumbnailsObject

Returns the value of attribute thumbnails.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def thumbnails
  @thumbnails
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def type
  @type
end

#uidObject

Returns the value of attribute uid.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def uid
  @uid
end

#volumeObject

Returns the value of attribute volume.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def volume
  @volume
end

#watermarksObject

Returns the value of attribute watermarks.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def watermarks
  @watermarks
end

#widthObject

Returns the value of attribute width.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def width
  @width
end

#work_dirObject

Returns the value of attribute work_dir.



13
14
15
# File 'lib/video_converter/output.rb', line 13

def work_dir
  @work_dir
end

Instance Method Details

#output_group(outputs) ⇒ Object



46
47
48
49
# File 'lib/video_converter/output.rb', line 46

def output_group(outputs)
  paths = streams.map { |stream| stream[:path] }
  outputs.select { |output| paths.include?(output.filename) }.unshift(self)
end