Module: RVideo::Tools::AbstractTool::InstanceMethods
- Included in:
- Ffmpeg, Ffmpeg2theora, Flvtool2, Mencoder, Mp4box, Mp4creator, Mplayer, QtFaststart, Yamdi
- Defined in:
- lib/rvideo/tools/abstract_tool.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#original ⇒ Object
writeonly
Sets the attribute original.
-
#raw_result ⇒ Object
readonly
Returns the value of attribute raw_result.
Class Method Summary collapse
-
.abstract_attribute_formatter(*names) ⇒ Object
Defines abstract methods in the convention of “format_#attribute” which are meant to be redefined by classes including this behavior.
Instance Method Summary collapse
-
#audio_bit_rate ⇒ Object
Audio bit rate.
-
#audio_channels ⇒ Object
Audio channels.
-
#audio_sample_rate ⇒ Object
Audio sample rate.
- #calculate_height(ow, oh, w) ⇒ Object
- #calculate_width(ow, oh, h) ⇒ Object
-
#deinterlace ⇒ Object
Resolution.
-
#do_execute(command) ⇒ Object
Wrapper around the system call, for whenever we need to hook on or redefine this without messing with Kernel.
- #execute ⇒ Object
-
#fps ⇒ Object
FPS aka framerate.
- #get_audio_bit_rate ⇒ Object
- #get_audio_channels ⇒ Object
- #get_audio_sample_rate ⇒ Object
- #get_deinterlace ⇒ Object
- #get_fit_to_height_resolution ⇒ Object
- #get_fit_to_width_resolution ⇒ Object
- #get_fps ⇒ Object
- #get_letterbox_resolution ⇒ Object
- #get_mono_audio ⇒ Object
- #get_original_fps ⇒ Object
- #get_original_resolution ⇒ Object
- #get_resolution ⇒ Object
- #get_specific_audio_bit_rate ⇒ Object
- #get_specific_audio_sample_rate ⇒ Object
- #get_specific_fps ⇒ Object
- #get_specific_resolution ⇒ Object
- #get_stereo_audio ⇒ Object
- #get_video_bit_rate ⇒ Object
- #get_video_bit_rate_max ⇒ Object
- #get_video_bit_rate_min ⇒ Object
- #get_video_bit_rate_tolerance ⇒ Object
- #get_video_quality ⇒ Object
- #initialize(raw_command, options = {}) ⇒ Object
- #resolution ⇒ Object
-
#temp_dir ⇒ Object
Magic parameters.
- #valid_dimension?(dim) ⇒ Boolean
- #video_bit_rate ⇒ Object
- #video_bit_rate_max ⇒ Object
- #video_bit_rate_min ⇒ Object
- #video_bit_rate_tolerance ⇒ Object
-
#video_quality ⇒ Object
Video quality.
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
43 44 45 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 43 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 43 def end |
#original=(value) ⇒ Object (writeonly)
Sets the attribute original
44 45 46 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 44 def original=(value) @original = value end |
#raw_result ⇒ Object (readonly)
Returns the value of attribute raw_result.
43 44 45 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 43 def raw_result @raw_result end |
Class Method Details
.abstract_attribute_formatter(*names) ⇒ Object
Defines abstract methods in the convention of “format_#attribute” which are meant to be redefined by classes including this behavior.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 25 def self.abstract_attribute_formatter(*names) names.map { |n| "format_#{n}" }.each do |name| class_eval %{ def #{name}(params = {}) raise ParameterError, "The #{self.class} tool has not implemented the :#{name} method." end }, __FILE__, __LINE__ end end |
Instance Method Details
#audio_bit_rate ⇒ Object
Audio bit rate
269 270 271 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 269 def audio_bit_rate format_audio_bit_rate(get_audio_bit_rate) end |
#audio_channels ⇒ Object
Audio channels
234 235 236 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 234 def audio_channels format_audio_channels(get_audio_channels) end |
#audio_sample_rate ⇒ Object
Audio sample rate
286 287 288 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 286 def audio_sample_rate format_audio_sample_rate(get_audio_sample_rate) end |
#calculate_height(ow, oh, w) ⇒ Object
222 223 224 225 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 222 def calculate_height(ow, oh, w) h = (w.to_f / (ow.to_f / oh.to_f)).to_i (h.to_f / 16).round * 16 end |
#calculate_width(ow, oh, h) ⇒ Object
217 218 219 220 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 217 def calculate_width(ow, oh, h) w = ((ow.to_f / oh.to_f) * h.to_f).to_i (w.to_f / 16).round * 16 end |
#deinterlace ⇒ Object
Resolution
122 123 124 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 122 def deinterlace format_deinterlace(get_deinterlace) end |
#do_execute(command) ⇒ Object
Wrapper around the system call, for whenever we need to hook on or redefine this without messing with Kernel
77 78 79 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 77 def do_execute(command) system command end |
#execute ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 52 def execute @output_params = {} # Dump the log output into a temp file log_temp_file_name = "/tmp/transcode_output_#{Time.now.to_i}.txt" final_command = "#{@command} 2>#{log_temp_file_name}" RVideo.logger.info("\nExecuting Command: #{final_command}\n") do_execute final_command populate_raw_result(log_temp_file_name) RVideo.logger.info("Result: \n#{@raw_result}") parse_result(@raw_result) # Cleanup log file begin File.delete(log_temp_file_name) rescue Exception => e RVideo.logger.error("Failed to delete output log file: #{log_temp_file_name}, e=#{e}") end end |
#fps ⇒ Object
FPS aka framerate
95 96 97 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 95 def fps format_fps(get_fps) end |
#get_audio_bit_rate ⇒ Object
273 274 275 276 277 278 279 280 281 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 273 def get_audio_bit_rate bit_rate = ['audio_bit_rate'] || "" case bit_rate when "" {} else get_specific_audio_bit_rate end end |
#get_audio_channels ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 238 def get_audio_channels channels = ['audio_channels'] || "" case channels when "stereo" get_stereo_audio when "mono" get_mono_audio else {} end end |
#get_audio_sample_rate ⇒ Object
290 291 292 293 294 295 296 297 298 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 290 def get_audio_sample_rate sample_rate = ['audio_sample_rate'] || "" case sample_rate when "" {} else get_specific_audio_sample_rate end end |
#get_deinterlace ⇒ Object
126 127 128 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 126 def get_deinterlace { :deinterlace => ['deinterlace'] ? true : false } end |
#get_fit_to_height_resolution ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 166 def get_fit_to_height_resolution h = ['height'] raise TranscoderError::ParameterError, "invalid height of '#{h}' for fit to height" unless valid_dimension?(h) w = calculate_width(@original.width, @original.height, h) { :scale => { :width => w, :height => h } } end |
#get_fit_to_width_resolution ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 155 def get_fit_to_width_resolution w = ['width'] raise TranscoderError::ParameterError, "invalid width of '#{w}' for fit to width" unless valid_dimension?(w) h = calculate_height(@original.width, @original.height, w) { :scale => { :width => w, :height => h } } end |
#get_fps ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 99 def get_fps inspect_original if @original.nil? fps = ['fps'] || "" case fps when "copy" get_original_fps else get_specific_fps end end |
#get_letterbox_resolution ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 177 def get_letterbox_resolution lw = ['width'].to_i lh = ['height'].to_i raise TranscoderError::ParameterError, "invalid width of '#{lw}' for letterbox" unless valid_dimension?(lw) raise TranscoderError::ParameterError, "invalid height of '#{lh}' for letterbox" unless valid_dimension?(lh) w = calculate_width(@original.width, @original.height, lh) h = calculate_height(@original.width, @original.height, lw) if w > lw w = lw h = calculate_height(@original.width, @original.height, lw) else h = lh w = calculate_width(@original.width, @original.height, lh) end { :scale => { :width => w, :height => h }, :letterbox => { :width => lw, :height => lh } } end |
#get_mono_audio ⇒ Object
254 255 256 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 254 def get_mono_audio { :channels => "1" } end |
#get_original_fps ⇒ Object
110 111 112 113 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 110 def get_original_fps return {} if @original.fps.nil? { :fps => @original.fps } end |
#get_original_resolution ⇒ Object
201 202 203 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 201 def get_original_resolution { :scale => { :width => @original.width, :height => @original.height } } end |
#get_resolution ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 134 def get_resolution inspect_original if @original.nil? case ['resolution'] when "copy" then get_original_resolution when "width" then get_fit_to_width_resolution when "height" then get_fit_to_height_resolution when "letterbox" then get_letterbox_resolution else if ["width"] and not ["height"] get_fit_to_width_resolution elsif ["height"] and not ["width"] get_fit_to_height_resolution elsif ["width"] and ["height"] get_specific_resolution else get_original_resolution end end end |
#get_specific_audio_bit_rate ⇒ Object
258 259 260 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 258 def get_specific_audio_bit_rate { :bit_rate => ['audio_bit_rate'] } end |
#get_specific_audio_sample_rate ⇒ Object
262 263 264 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 262 def get_specific_audio_sample_rate { :sample_rate => ['audio_sample_rate'] } end |
#get_specific_fps ⇒ Object
115 116 117 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 115 def get_specific_fps { :fps => ['fps'] } end |
#get_specific_resolution ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 205 def get_specific_resolution w = ['width'] h = ['height'] raise TranscoderError::ParameterError, "invalid width of '#{w}' for specific resolution" unless valid_dimension?(w) raise TranscoderError::ParameterError, "invalid height of '#{h}' for specific resolution" unless valid_dimension?(h) { :scale => { :width => w, :height => h } } end |
#get_stereo_audio ⇒ Object
250 251 252 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 250 def get_stereo_audio { :channels => "2" } end |
#get_video_bit_rate ⇒ Object
320 321 322 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 320 def get_video_bit_rate { :video_bit_rate => ["video_bit_rate"] } end |
#get_video_bit_rate_max ⇒ Object
344 345 346 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 344 def get_video_bit_rate_max { :video_bit_rate_max => ["video_bit_rate_max"] } end |
#get_video_bit_rate_min ⇒ Object
336 337 338 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 336 def get_video_bit_rate_min { :video_bit_rate_min => ["video_bit_rate_min"] } end |
#get_video_bit_rate_tolerance ⇒ Object
328 329 330 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 328 def get_video_bit_rate_tolerance { :video_bit_rate_tolerance => ["video_bit_rate_tolerance"] } end |
#get_video_quality ⇒ Object
307 308 309 310 311 312 313 314 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 307 def get_video_quality quality = ['video_quality'] || 'medium' { :video_quality => quality }. merge!(get_fps). merge!(get_resolution). merge!(get_video_bit_rate) end |
#initialize(raw_command, options = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 46 def initialize(raw_command, = {}) @raw_command = raw_command = HashWithIndifferentAccess.new() @command = interpolate_variables(raw_command) end |
#resolution ⇒ Object
130 131 132 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 130 def resolution format_resolution(get_resolution) end |
#temp_dir ⇒ Object
Magic parameters
84 85 86 87 88 89 90 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 84 def temp_dir if ['output_file'] "#{File.dirname(@options['output_file'])}/" else "" end end |
#valid_dimension?(dim) ⇒ Boolean
227 228 229 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 227 def valid_dimension?(dim) dim.to_i > 0 end |
#video_bit_rate ⇒ Object
316 317 318 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 316 def video_bit_rate format_video_bit_rate(get_video_bit_rate) end |
#video_bit_rate_max ⇒ Object
340 341 342 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 340 def video_bit_rate_max format_video_bit_rate_max(get_video_bit_rate_max) end |
#video_bit_rate_min ⇒ Object
332 333 334 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 332 def video_bit_rate_min format_video_bit_rate_min(get_video_bit_rate_min) end |
#video_bit_rate_tolerance ⇒ Object
324 325 326 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 324 def video_bit_rate_tolerance format_video_bit_rate_tolerance(get_video_bit_rate_tolerance) end |
#video_quality ⇒ Object
Video quality
303 304 305 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 303 def video_quality format_video_quality(get_video_quality) end |