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.
Instance Method Summary collapse
- #audio_bit_rate ⇒ Object
- #audio_channels ⇒ Object
- #audio_sample_rate ⇒ Object
- #calculate_height(ow, oh, w) ⇒ Object
- #calculate_width(ow, oh, h) ⇒ Object
-
#execute ⇒ Object
Execute the command and parse the result.
- #format_audio_bit_rate(params = {}) ⇒ Object
- #format_audio_channels(params = {}) ⇒ Object
- #format_audio_sample_rate(params = {}) ⇒ Object
- #format_fps(params = {}) ⇒ Object
- #format_resolution(params = {}) ⇒ Object
- #fps ⇒ Object
- #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_quality ⇒ Object
- #initialize(raw_command, options = {}) ⇒ Object
- #resolution ⇒ Object
-
#temp_dir ⇒ Object
Magic parameters.
- #valid_dimension?(dim) ⇒ Boolean
- #video_quality ⇒ Object
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
24 25 26 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 24 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 24 def @options end |
#original=(value) ⇒ Object (writeonly)
Sets the attribute original
25 26 27 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 25 def original=(value) @original = value end |
#raw_result ⇒ Object (readonly)
Returns the value of attribute raw_result.
24 25 26 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 24 def raw_result @raw_result end |
Instance Method Details
#audio_bit_rate ⇒ Object
134 135 136 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 134 def audio_bit_rate format_audio_bit_rate(get_audio_bit_rate) end |
#audio_channels ⇒ Object
118 119 120 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 118 def audio_channels format_audio_channels(get_audio_channels) end |
#audio_sample_rate ⇒ Object
148 149 150 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 148 def audio_sample_rate format_audio_sample_rate(get_audio_sample_rate) end |
#calculate_height(ow, oh, w) ⇒ Object
257 258 259 260 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 257 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
252 253 254 255 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 252 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 |
#execute ⇒ Object
Execute the command and parse the result.
def execute
@output_params = {}
final_command = "#{@command} 2>&1"
Transcoder.logger.info("\nExecuting Command: #{final_command}\n")
@raw_result = `#{final_command}`
Transcoder.logger.info("Result: \n#{@raw_result}")
parse_result(@raw_result)
end
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 45 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}" Transcoder.logger.info("\nExecuting Command: #{final_command}\n") `#{final_command}` populate_raw_result(log_temp_file_name) Transcoder.logger.info("Result: \n#{@raw_result}") parse_result(@raw_result) # Cleanup log file begin File.delete(log_temp_file_name) rescue Exception => e Transcoder.logger.error("Failed to delete output log file: #{log_temp_file_name}, e=#{e}") end end |
#format_audio_bit_rate(params = {}) ⇒ Object
280 281 282 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 280 def format_audio_bit_rate(params={}) raise ParameterError, "The #{self.class} tool has not implemented the format_audio_bit_rate method." end |
#format_audio_channels(params = {}) ⇒ Object
276 277 278 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 276 def format_audio_channels(params={}) raise ParameterError, "The #{self.class} tool has not implemented the format_audio_channels method." end |
#format_audio_sample_rate(params = {}) ⇒ Object
284 285 286 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 284 def format_audio_sample_rate(params={}) raise ParameterError, "The #{self.class} tool has not implemented the format_audio_sample_rate method." end |
#format_fps(params = {}) ⇒ Object
272 273 274 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 272 def format_fps(params={}) raise ParameterError, "The #{self.class} tool has not implemented the format_fps method." end |
#format_resolution(params = {}) ⇒ Object
268 269 270 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 268 def format_resolution(params={}) raise ParameterError, "The #{self.class} tool has not implemented the format_resolution method." end |
#fps ⇒ Object
80 81 82 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 80 def fps format_fps(get_fps) end |
#get_audio_bit_rate ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 138 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
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 122 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
152 153 154 155 156 157 158 159 160 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 152 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
183 184 185 186 187 188 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 183 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
176 177 178 179 180 181 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 176 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
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 84 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
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 190 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
240 241 242 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 240 def get_mono_audio {:channels => "1"} end |
#get_original_fps ⇒ Object
219 220 221 222 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 219 def get_original_fps return {} if @original.fps.nil? {:fps => @original.fps} end |
#get_original_resolution ⇒ Object
207 208 209 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 207 def get_original_resolution {:scale => {:width => @original.width, :height => @original.height}} end |
#get_resolution ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 100 def get_resolution inspect_original if @original.nil? resolution_setting = @options['resolution'] || "" case resolution_setting when "copy" get_original_resolution when "width" get_fit_to_width_resolution when "height" get_fit_to_height_resolution when "letterbox" get_letterbox_resolution else get_specific_resolution end end |
#get_specific_audio_bit_rate ⇒ Object
244 245 246 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 244 def get_specific_audio_bit_rate {:bit_rate => @options['audio_bit_rate']} end |
#get_specific_audio_sample_rate ⇒ Object
248 249 250 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 248 def get_specific_audio_sample_rate {:sample_rate => @options['audio_sample_rate']} end |
#get_specific_fps ⇒ Object
224 225 226 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 224 def get_specific_fps {:fps => @options['fps']} end |
#get_specific_resolution ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 211 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
def get_video_quality
fps = @options['fps'] || @original.fps
raise TranscoderError::ParameterError, "could not find fps in order to determine video quality" if fps.nil?
width = @original.width
height = @
format_video_quality({:quality => @options['video_quality'], :bit_rate => @options['video_bit_rate']})
end
236 237 238 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 236 def get_stereo_audio {:channels => "2"} end |
#get_video_quality ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 166 def get_video_quality inspect_original if @original.nil? quality = @options['video_quality'] || 'medium' video_bit_rate = @options['video_bit_rate'] || nil h = {:video_quality => quality, :video_bit_rate => video_bit_rate} h.merge!(get_fps).merge!(get_resolution) end |
#initialize(raw_command, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 27 def initialize(raw_command, = {}) @raw_command = raw_command @options = HashWithIndifferentAccess.new() @command = interpolate_variables(raw_command) end |
#resolution ⇒ Object
96 97 98 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 96 def resolution format_resolution(get_resolution) end |
#temp_dir ⇒ Object
Magic parameters
71 72 73 74 75 76 77 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 71 def temp_dir if @options['output_file'] "#{File.dirname(@options['output_file'])}/" else "" end end |
#valid_dimension?(dim) ⇒ Boolean
263 264 265 266 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 263 def valid_dimension?(dim) return false if dim.to_i <= 0 return true end |
#video_quality ⇒ Object
162 163 164 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 162 def video_quality format_video_quality(get_video_quality) end |