lib/falcon/encoder.rb in falcon-0.1.2 vs lib/falcon/encoder.rb in falcon-0.1.3

- old
+ new

@@ -60,11 +60,10 @@ def profile_options(input_file, output_file) self.profile.encode_options.merge({ :input_file => input_file, :output_file => output_file, :resolution => self.ffmpeg_resolution - #:resolution_and_padding => self.ffmpeg_resolution_and_padding_no_cropping }) end # A hash of metadatas for video: # @@ -131,50 +130,50 @@ self.width ||= profile.width self.height ||= profile.height end end + # Calculate resolution and any padding def ffmpeg_resolution_and_padding_no_cropping(v_width, v_height) - # Calculate resolution and any padding - in_w = v_width.to_f #self.video.width.to_f - in_h = v_height.to_f #self.video.height.to_f + in_w = v_width.to_f + in_h = v_height.to_f out_w = self.width.to_f out_h = self.height.to_f begin aspect = in_w / in_h aspect_inv = in_h / in_w rescue - #Merb.logger.error "Couldn't do w/h to caculate aspect. Just using the output resolution now." - @ffmpeg_resolution = %(#{self.width}x#{self.height} ) + Rails.logger.error "Couldn't do w/h to caculate aspect. Just using the output resolution now." + @ffmpeg_resolution = "#{self.width}x#{self.height}" return end height = (out_w / aspect.to_f).to_i height -= 1 if height % 2 == 1 - @ffmpeg_resolution = %(#{self.width}x#{height} ) + @ffmpeg_resolution = "#{self.width}x#{height}" # Keep the video's original width if the height if height > out_h width = (out_h / aspect_inv.to_f).to_i width -= 1 if width % 2 == 1 - @ffmpeg_resolution = %(#{width}x#{self.height} ) + @ffmpeg_resolution = "#{width}x#{self.height}" self.width = width - self.save + self.save(:validate => false) # Otherwise letterbox it elsif height < out_h pad = ((out_h - height.to_f) / 2.0).to_i pad -= 1 if pad % 2 == 1 - @ffmpeg_padding = %(-padtop #{pad} -padbottom #{pad}) + @ffmpeg_padding = "-vf pad=#{self.width}:#{height + pad}:0:#{pad / 2}" end end - def encode_source - #stream = transcoder.source.video_stream - ffmpeg_resolution_and_padding_no_cropping(self.width, self.height) + def encode_source + stream = transcoder.source.video_stream + ffmpeg_resolution_and_padding_no_cropping(stream.width, stream.height) options = self.profile_options(self.source_path, output_path) begin transcoder.convert(output_path, options) do |command| # Audo @@ -198,10 +197,10 @@ metadata_options.each do |key, value| command << "-metadata #{key}=\"#{value}\"" end end - command << @ffmpeg_padding + command << self.ffmpeg_padding command << "-y" end rescue ::WebVideo::CommandLineError => e ::WebVideo.logger.error("Unable to transcode video #{self.id}: #{e.class} - #{e.message}") return false