lib/carrierwave/video/ffmpeg_options.rb in carrierwave-video-0.2.2 vs lib/carrierwave/video/ffmpeg_options.rb in carrierwave-video-0.2.3

- old
+ new

@@ -1,15 +1,16 @@ module CarrierWave module Video class FfmpegOptions attr_reader :watermark_path, :watermark_position, :watermark_pixels, - :format, :resolution, :callbacks + :format, :resolution, :custom, :callbacks def initialize(format, options) @format = format.to_s @watermark = options[:watermark].present? @resolution = options[:resolution] || "640x360" + @custom = options[:custom] @callbacks = options[:callbacks] || {} @logger = options[:logger] @unparsed = options if watermark? @@ -30,32 +31,37 @@ def encoder_options {preserve_aspect_ratio: :width} end def format_options - format_options = case format - when "mp4" - { - video_codec: 'libx264', - audio_codec: 'libfaac', - custom: "-qscale 0 -vpre slow -vpre baseline -g 30 #{watermark_params}" - } - when "webm" - { - video_codec: 'libvpx', - audio_codec: 'libvorbis', - custom: "-b 1500k -ab 160000 -f webm -g 30 #{watermark_params}" - } - when "ogv" - { - video_codec: 'libtheora', - audio_codec: 'libvorbis', - custom: "-b 1500k -ab 160000 -g 30 #{watermark_params}" - } - else - {} + @format_options ||= begin + result = case format + when "mp4" + { + video_codec: 'libx264', + audio_codec: 'libfaac', + custom: "-qscale 0 -vpre slow -vpre baseline -g 30 #{watermark_params}" + } + when "webm" + { + video_codec: 'libvpx', + audio_codec: 'libvorbis', + custom: "-b 1500k -ab 160000 -f webm -g 30 #{watermark_params}" + } + when "ogv" + { + video_codec: 'libtheora', + audio_codec: 'libvorbis', + custom: "-b 1500k -ab 160000 -g 30 #{watermark_params}" + } + else + {} + end + + { resolution: resolution }.merge(result).tap do |h| + h[:custom] = "#{custom} #{watermark_params}".strip if custom.present? + end end - { resolution: resolution }.merge(format_options) end def watermark? @watermark end