Class: Libis::Format::Converter::VideoConverter

Inherits:
Base
  • Object
show all
Defined in:
lib/libis/format/converter/video_converter.rb

Instance Attribute Summary

Attributes inherited from Base

#flags, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, using_temp, #using_temp

Constructor Details

#initializeVideoConverter

Returns a new instance of VideoConverter.



21
22
23
# File 'lib/libis/format/converter/video_converter.rb', line 21

def initialize
  super
end

Class Method Details

.input_typesObject



12
13
14
# File 'lib/libis/format/converter/video_converter.rb', line 12

def self.input_types
  [:WEBM, :MP4, :MPG, :MKV, :MJP2, :QTFF, :AVI, :OGGV, :WMV, :DV, :FLV, :SWF]
end

.output_types(format = nil) ⇒ Object



16
17
18
19
# File 'lib/libis/format/converter/video_converter.rb', line 16

def self.output_types(format = nil)
  return [] unless input_types.include?(format)
  [:GIF, :WEBM, :MP4, :MPG, :MKV, :MJP2, :QTFF, :AVI, :OGGV, :WMV, :DV, :FLV, :SWF]
end

Instance Method Details

#assemble_and_convert(sources, target) ⇒ Object



186
187
188
189
190
191
192
193
194
195
# File 'lib/libis/format/converter/video_converter.rb', line 186

def assemble_and_convert(sources, target)
  Tempfile.create(%w(list .txt)) do |f|
    sources.each {|src| f.puts src}
    opts[:global] ||= []
    opts[:global] += %w(-f concat)
    f.close
    target = convert_file(f.to_path, target)
  end
  target
end

#audio_bitrate(value) ⇒ Object



61
62
63
# File 'lib/libis/format/converter/video_converter.rb', line 61

def audio_bitrate(value)
  @options[:audio_bitrate] = value.to_s
end

#audio_channels(value) ⇒ Object



33
34
35
# File 'lib/libis/format/converter/video_converter.rb', line 33

def audio_channels(value)
  @options[:audio_channels] = value.to_s
end

#audio_codec(codec) ⇒ Object



37
38
39
# File 'lib/libis/format/converter/video_converter.rb', line 37

def audio_codec(codec)
  @options[:audio_codec] = codec
end

#audio_preset(name) ⇒ Object

Parameters:

  • name (String)

    name of an audio preset. See FFMpeg documentation for more info



141
142
143
# File 'lib/libis/format/converter/video_converter.rb', line 141

def audio_preset(name)
  @options[:audio_preset] = name
end

#audio_quality(value) ⇒ Object



53
54
55
# File 'lib/libis/format/converter/video_converter.rb', line 53

def audio_quality(value)
  @options[:audio_quality] = value.to_s
end

#constant_rate_factor(value) ⇒ Object



69
70
71
# File 'lib/libis/format/converter/video_converter.rb', line 69

def constant_rate_factor(value)
  @options[:crf] = value.to_s
end

#convert(source, target, _format, opts = {}) ⇒ Object

def video_encoder(value)

@options[:video_encoder] = value

end

def audio_encoder(value)

@options[:audio_encoder] = value

end

def encoder_options(value)

@options[:encoder_options] = value

end



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/libis/format/converter/video_converter.rb', line 162

def convert(source, target, _format, opts = {})
  super

  FileUtils.mkpath(File.dirname(target))

  if source.is_a? Array

    assemble_and_convert(source, target)

  elsif File.directory?(source)

    sources = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
    assemble_and_convert(sources, target)

  else

    convert_file(source, target)

  end

  target

end

#duration(seconds) ⇒ Object



49
50
51
# File 'lib/libis/format/converter/video_converter.rb', line 49

def duration(seconds)
  @options[:duration] = seconds.to_s
end

#format(format) ⇒ Object



29
30
31
# File 'lib/libis/format/converter/video_converter.rb', line 29

def format(format)
  @options[:format] = format
end

#frame_rate(value) ⇒ Object



73
74
75
# File 'lib/libis/format/converter/video_converter.rb', line 73

def frame_rate(value)
  @options[:frame_rate] = value.to_s
end

#preset(name) ⇒ Object

Parameters:

  • name (String)

    name of a preset. See FFMpeg documentation for more info



136
137
138
# File 'lib/libis/format/converter/video_converter.rb', line 136

def preset(name)
  @options[:preset] = name
end

#quiet(v) ⇒ Object



25
26
27
# File 'lib/libis/format/converter/video_converter.rb', line 25

def quiet(v)
  @flags[:quiet] = !!v
end

#sampling_freq(value) ⇒ Object



77
78
79
# File 'lib/libis/format/converter/video_converter.rb', line 77

def sampling_freq(value)
  @options[:sampling_freq] = value.to_s
end

#scale(width_x_height) ⇒ Object



81
82
83
# File 'lib/libis/format/converter/video_converter.rb', line 81

def scale(width_x_height)
  @options[:scale] = width_x_height
end

#start(seconds) ⇒ Object



45
46
47
# File 'lib/libis/format/converter/video_converter.rb', line 45

def start(seconds)
  @options[:start] = seconds.to_s
end

#video_bitrate(value) ⇒ Object



65
66
67
# File 'lib/libis/format/converter/video_converter.rb', line 65

def video_bitrate(value)
  @options[:video_bitrate] = value.to_s
end

#video_codec(codec) ⇒ Object



41
42
43
# File 'lib/libis/format/converter/video_converter.rb', line 41

def video_codec(codec)
  @options[:video_codec] = codec
end

#video_preset(name) ⇒ Object

Parameters:

  • name (String)

    name of a video preset. See FFMpeg documentation for more info



146
147
148
# File 'lib/libis/format/converter/video_converter.rb', line 146

def video_preset(name)
  @options[:video_preset] = name
end

#video_quality(value) ⇒ Object



57
58
59
# File 'lib/libis/format/converter/video_converter.rb', line 57

def video_quality(value)
  @options[:video_quality] = value.to_s
end

#watermark_image(file) ⇒ Object

Parameters:

  • file (String)

    Image file path to use as watermark



86
87
88
# File 'lib/libis/format/converter/video_converter.rb', line 86

def watermark_image(file)
  @options[:watermark_image] = file
end

#watermark_opacity(value) ⇒ Object

Parameters:

  • value (Number)

    watermark opacity (0-1) with 0 = invisible and 1 = 100% opaque. Default: 0.5



123
124
125
# File 'lib/libis/format/converter/video_converter.rb', line 123

def watermark_opacity(value)
  @options[:watermark_opacity] = value.to_f
end

#watermark_position(value) ⇒ Object

Parameters:

  • value (String)

    one of ‘bottom_left’ (default), ‘top_left’, ‘bottom_right’, ‘top_right’, ‘center’



118
119
120
# File 'lib/libis/format/converter/video_converter.rb', line 118

def watermark_position(value)
  @options[:watermark_position] = value
end

#watermark_text(value) ⇒ Object

Parameters:

  • value (String)

    text for watermark. No watermark if nil (default)



91
92
93
# File 'lib/libis/format/converter/video_converter.rb', line 91

def watermark_text(value)
  @options[:watermark_text] = value
end

#watermark_text_color(value) ⇒ Object

Parameters:

  • value (String)

    Text color for the watermark text. Default: white



102
103
104
# File 'lib/libis/format/converter/video_converter.rb', line 102

def watermark_text_color(value)
  @options[:watermark_text_color] = value
end

#watermark_text_shadow_color(value) ⇒ Object

Parameters:

  • value (String)

    Text color for the watermark text shadow. Default: black



107
108
109
# File 'lib/libis/format/converter/video_converter.rb', line 107

def watermark_text_shadow_color(value)
  @options[:watermark_text_shadow_color] = value
end

#watermark_text_shadow_offset(value) ⇒ Object

If the offset is set to 0, no shadow will be printed

Parameters:

  • value (Integer)

    Offset of the watermark text shadow. Used for both x and y offset; default: 1



113
114
115
# File 'lib/libis/format/converter/video_converter.rb', line 113

def watermark_text_shadow_offset(value)
  @options[:watermark_text_offset] = value.to_i
end

#watermark_text_size(value) ⇒ Object

Note that the font is selected by the Config setting

Parameters:

  • value (Integer)

    Font size for watermark text. Default: 10



97
98
99
# File 'lib/libis/format/converter/video_converter.rb', line 97

def watermark_text_size(value)
  @options[:watermark_text_size] = value.to_i
end

#web_stream(value) ⇒ Object

Parameters:

  • value (Boolean)

    If set to true automatically selects optimal format for web viewing. Default: false



128
129
130
131
132
133
# File 'lib/libis/format/converter/video_converter.rb', line 128

def web_stream(value)
  if value
    @options[:video_codec] = 'h264'
    @options[:audio_codec] = 'acc'
  end
end