Module: RVideo::Tools::AbstractTool::InstanceMethods
- Included in:
- Ffmpeg, Ffmpeg2theora, Flvtool2, Mencoder, Mp4box, Mp4creator, Mplayer, QtFaststart, Segmenter, 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.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#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 @options 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 |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
43 44 45 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 43 def progress @progress 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
274 275 276 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 274 def audio_bit_rate format_audio_bit_rate(get_audio_bit_rate) end |
#audio_channels ⇒ Object
Audio channels
239 240 241 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 239 def audio_channels format_audio_channels(get_audio_channels) end |
#audio_sample_rate ⇒ Object
Audio sample rate
291 292 293 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 291 def audio_sample_rate format_audio_sample_rate(get_audio_sample_rate) end |
#calculate_height(ow, oh, w) ⇒ Object
227 228 229 230 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 227 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
222 223 224 225 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 222 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
127 128 129 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 127 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
82 83 84 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 82 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 74 75 76 77 78 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 52 def execute @output_params = {} if block_given? and self.respond_to?(:execute_with_progress) execute_with_progress do |progress| yield progress end else # Dump the log output into a temp file log_temp_file_name = "/tmp/transcode_output_#{Time.now.to_i}_#{rand(100)}.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) end 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
100 101 102 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 100 def fps format_fps(get_fps) end |
#get_audio_bit_rate ⇒ Object
278 279 280 281 282 283 284 285 286 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 278 def get_audio_bit_rate bit_rate = @options['audio_bit_rate'] || "" case bit_rate when "" {} else get_specific_audio_bit_rate end end |
#get_audio_channels ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 243 def get_audio_channels channels = @options['audio_channels'] || "" case channels when "stereo" get_stereo_audio when "mono" get_mono_audio else {} end end |
#get_audio_sample_rate ⇒ Object
295 296 297 298 299 300 301 302 303 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 295 def get_audio_sample_rate sample_rate = @options['audio_sample_rate'] || "" case sample_rate when "" {} else get_specific_audio_sample_rate end end |
#get_deinterlace ⇒ Object
131 132 133 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 131 def get_deinterlace { :deinterlace => @options['deinterlace'] ? true : false } end |
#get_fit_to_height_resolution ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 171 def get_fit_to_height_resolution h = @options['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
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 160 def get_fit_to_width_resolution w = @options['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
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 104 def get_fps inspect_original if @original.nil? fps = @options['fps'] || "" case fps when "copy" get_original_fps else get_specific_fps end end |
#get_letterbox_resolution ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 182 def get_letterbox_resolution lw = @options['width'].to_i lh = @options['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
259 260 261 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 259 def get_mono_audio { :channels => "1" } end |
#get_original_fps ⇒ Object
115 116 117 118 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 115 def get_original_fps return {} if @original.fps.nil? { :fps => @original.fps } end |
#get_original_resolution ⇒ Object
206 207 208 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 206 def get_original_resolution { :scale => { :width => @original.width, :height => @original.height } } end |
#get_resolution ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 139 def get_resolution inspect_original if @original.nil? case @options['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 @options["width"] and not @options["height"] get_fit_to_width_resolution elsif @options["height"] and not @options["width"] get_fit_to_height_resolution elsif @options["width"] and @options["height"] get_specific_resolution else get_original_resolution end end end |
#get_specific_audio_bit_rate ⇒ Object
263 264 265 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 263 def get_specific_audio_bit_rate { :bit_rate => @options['audio_bit_rate'] } end |
#get_specific_audio_sample_rate ⇒ Object
267 268 269 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 267 def get_specific_audio_sample_rate { :sample_rate => @options['audio_sample_rate'] } end |
#get_specific_fps ⇒ Object
120 121 122 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 120 def get_specific_fps { :fps => @options['fps'] } end |
#get_specific_resolution ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 210 def get_specific_resolution w = @options['width'] h = @options['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
255 256 257 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 255 def get_stereo_audio { :channels => "2" } end |
#get_video_bit_rate ⇒ Object
325 326 327 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 325 def get_video_bit_rate { :video_bit_rate => @options["video_bit_rate"] } end |
#get_video_bit_rate_max ⇒ Object
349 350 351 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 349 def get_video_bit_rate_max { :video_bit_rate_max => @options["video_bit_rate_max"] } end |
#get_video_bit_rate_min ⇒ Object
341 342 343 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 341 def get_video_bit_rate_min { :video_bit_rate_min => @options["video_bit_rate_min"] } end |
#get_video_bit_rate_tolerance ⇒ Object
333 334 335 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 333 def get_video_bit_rate_tolerance { :video_bit_rate_tolerance => @options["video_bit_rate_tolerance"] } end |
#get_video_quality ⇒ Object
312 313 314 315 316 317 318 319 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 312 def get_video_quality quality = @options['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 @options = HashWithIndifferentAccess.new() @command = interpolate_variables(raw_command) end |
#resolution ⇒ Object
135 136 137 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 135 def resolution format_resolution(get_resolution) end |
#temp_dir ⇒ Object
Magic parameters
89 90 91 92 93 94 95 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 89 def temp_dir if @options['output_file'] "#{File.dirname(@options['output_file'])}/" else "" end end |
#valid_dimension?(dim) ⇒ Boolean
232 233 234 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 232 def valid_dimension?(dim) dim.to_i > 0 end |
#video_bit_rate ⇒ Object
321 322 323 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 321 def video_bit_rate format_video_bit_rate(get_video_bit_rate) end |
#video_bit_rate_max ⇒ Object
345 346 347 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 345 def video_bit_rate_max format_video_bit_rate_max(get_video_bit_rate_max) end |
#video_bit_rate_min ⇒ Object
337 338 339 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 337 def video_bit_rate_min format_video_bit_rate_min(get_video_bit_rate_min) end |
#video_bit_rate_tolerance ⇒ Object
329 330 331 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 329 def video_bit_rate_tolerance format_video_bit_rate_tolerance(get_video_bit_rate_tolerance) end |
#video_quality ⇒ Object
Video quality
308 309 310 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 308 def video_quality format_video_quality(get_video_quality) end |