lib/carrierwave/video/ffmpeg_options.rb in carrierwave-video-0.5.6 vs lib/carrierwave/video/ffmpeg_options.rb in carrierwave-video-0.6.0

- old
+ new

@@ -9,10 +9,11 @@ @custom = options[:custom] @callbacks = options[:callbacks] || {} @logger = options[:logger] @unparsed = options @progress = options[:progress] + @preserve_aspect_ratio = options[:preserve_aspect_ratio] || :width @format_options = defaults.merge(options) end def raw @@ -29,11 +30,11 @@ lambda { |val| model.send(@progress, *(args + [val])) } end end def encoder_options - { preserve_aspect_ratio: :width } + { preserve_aspect_ratio: @preserve_aspect_ratio } end # input def format_options @format_options @@ -41,20 +42,20 @@ # output def format_params params = @format_options.dup params.delete(:watermark) - params[:custom] = [params[:custom], watermark_params].compact.join(' ') + params[:custom] = params[:custom] + watermark_params params end def watermark? @format_options[:watermark].present? end def watermark_params - return nil unless watermark? + return [] unless watermark? @watermark_params ||= begin path = @format_options[:watermark][:path] position = @format_options[:watermark][:position].to_s || :bottom_right margin = @format_options[:watermark][:pixels_from_edge] || @format_options[:watermark][:margin] || 10 @@ -67,30 +68,30 @@ "#{margin}:#{margin}" when 'top_right' "main_w-overlay_w-#{margin}:#{margin}" end - "-vf \"movie=#{path} [logo]; [in][logo] overlay=#{positioning} [out]\"" + ["-vf", "\"movie=#{path} [logo]; [in][logo] overlay=#{positioning} [out]\""] end end private def defaults - @defaults ||= { resolution: '640x360', watermark: {} }.tap do |h| + @defaults ||= { resolution: @resolution, watermark: {} }.tap do |h| case format when 'mp4' h[:video_codec] = 'libx264' - h[:audio_codec] = 'libfaac' - h[:custom] = '-qscale 0 -preset slow -g 30' + h[:audio_codec] = 'aac' + h[:custom] = %w(-r 30 -strict -2 -map_metadata -1) when 'ogv' h[:video_codec] = 'libtheora' h[:audio_codec] = 'libvorbis' - h[:custom] = '-b 1500k -ab 160000 -g 30' + h[:custom] = %w(-b 1500k -ab 160000 -g 30) when 'webm' h[:video_codec] = 'libvpx' h[:audio_codec] = 'libvorbis' - h[:custom] = '-b 1500k -ab 160000 -f webm -g 30' + h[:custom] = %w(-b 1500k -ab 160000 -f webm) end end end end end