Module: RVideo::Tools::AbstractTool::InstanceMethods
- Included in:
- Ffmpeg, Ffmpeg2theora, Flvtool2, Mencoder, Mp4box, Mp4creator, Mplayer, 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
-
#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_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
Resolution.
-
#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 |
#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
261 262 263 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 261 def audio_bit_rate format_audio_bit_rate(get_audio_bit_rate) end |
#audio_channels ⇒ Object
Audio channels
226 227 228 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 226 def audio_channels format_audio_channels(get_audio_channels) end |
#audio_sample_rate ⇒ Object
Audio sample rate
278 279 280 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 278 def audio_sample_rate format_audio_sample_rate(get_audio_sample_rate) end |
#calculate_height(ow, oh, w) ⇒ Object
214 215 216 217 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 214 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
209 210 211 212 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 209 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 |
#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
265 266 267 268 269 270 271 272 273 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 265 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
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 230 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
282 283 284 285 286 287 288 289 290 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 282 def get_audio_sample_rate sample_rate = @options['audio_sample_rate'] || "" case sample_rate when "" {} else get_specific_audio_sample_rate end end |
#get_fit_to_height_resolution ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 158 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
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 147 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
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 = @options['fps'] || "" case fps when "copy" get_original_fps else get_specific_fps end end |
#get_letterbox_resolution ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 169 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
246 247 248 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 246 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
193 194 195 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 193 def get_original_resolution { :scale => { :width => @original.width, :height => @original.height } } end |
#get_resolution ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 126 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
250 251 252 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 250 def get_specific_audio_bit_rate { :bit_rate => @options['audio_bit_rate'] } end |
#get_specific_audio_sample_rate ⇒ Object
254 255 256 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 254 def get_specific_audio_sample_rate { :sample_rate => @options['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 => @options['fps'] } end |
#get_specific_resolution ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 197 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
242 243 244 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 242 def get_stereo_audio { :channels => "2" } end |
#get_video_bit_rate ⇒ Object
312 313 314 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 312 def get_video_bit_rate { :video_bit_rate => @options["video_bit_rate"] } end |
#get_video_bit_rate_max ⇒ Object
336 337 338 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 336 def get_video_bit_rate_max { :video_bit_rate_max => @options["video_bit_rate_max"] } end |
#get_video_bit_rate_min ⇒ Object
328 329 330 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 328 def get_video_bit_rate_min { :video_bit_rate_min => @options["video_bit_rate_min"] } end |
#get_video_bit_rate_tolerance ⇒ Object
320 321 322 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 320 def get_video_bit_rate_tolerance { :video_bit_rate_tolerance => @options["video_bit_rate_tolerance"] } end |
#get_video_quality ⇒ Object
299 300 301 302 303 304 305 306 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 299 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
Resolution
122 123 124 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 122 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 @options['output_file'] "#{File.dirname(@options['output_file'])}/" else "" end end |
#valid_dimension?(dim) ⇒ Boolean
219 220 221 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 219 def valid_dimension?(dim) dim.to_i > 0 end |
#video_bit_rate ⇒ Object
308 309 310 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 308 def video_bit_rate format_video_bit_rate(get_video_bit_rate) end |
#video_bit_rate_max ⇒ Object
332 333 334 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 332 def video_bit_rate_max format_video_bit_rate_max(get_video_bit_rate_max) end |
#video_bit_rate_min ⇒ Object
324 325 326 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 324 def video_bit_rate_min format_video_bit_rate_min(get_video_bit_rate_min) end |
#video_bit_rate_tolerance ⇒ Object
316 317 318 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 316 def video_bit_rate_tolerance format_video_bit_rate_tolerance(get_video_bit_rate_tolerance) end |
#video_quality ⇒ Object
Video quality
295 296 297 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 295 def video_quality format_video_quality(get_video_quality) end |