Class: CarrierWave::Video::FfmpegOptions
- Inherits:
-
Object
- Object
- CarrierWave::Video::FfmpegOptions
- Defined in:
- lib/carrierwave/video/ffmpeg_options.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#custom ⇒ Object
readonly
Returns the value of attribute custom.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
Instance Method Summary collapse
- #encoder_options ⇒ Object
-
#format_options ⇒ Object
input.
-
#format_params ⇒ Object
output.
-
#initialize(format, options) ⇒ FfmpegOptions
constructor
A new instance of FfmpegOptions.
- #logger(model) ⇒ Object
- #progress(model) ⇒ Object
- #raw ⇒ Object
- #watermark? ⇒ Boolean
- #watermark_params ⇒ Object
Constructor Details
#initialize(format, options) ⇒ FfmpegOptions
Returns a new instance of FfmpegOptions.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 6 def initialize(format, ) @format = format.to_s @resolution = [:resolution] || "640x360" @custom = [:custom] @callbacks = [:callbacks] || {} @logger = [:logger] @unparsed = @progress = [:progress] @format_options = defaults.merge() end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
4 5 6 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4 def callbacks @callbacks end |
#custom ⇒ Object (readonly)
Returns the value of attribute custom.
4 5 6 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4 def custom @custom end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4 def format @format end |
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
4 5 6 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4 def resolution @resolution end |
Instance Method Details
#encoder_options ⇒ Object
33 34 35 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 33 def { preserve_aspect_ratio: :width } end |
#format_options ⇒ Object
input
38 39 40 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 38 def @format_options end |
#format_params ⇒ Object
output
43 44 45 46 47 48 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 43 def format_params params = @format_options.dup params.delete(:watermark) params[:custom] = [params[:custom], watermark_params].compact.join(' ') params end |
#logger(model) ⇒ Object
22 23 24 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 22 def logger(model) model.send(@logger) if @logger.present? end |
#progress(model) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 26 def progress(model) if @progress args = model.method(@progress).arity == 3 ? [@format, @format_options] : [] lambda { |val| model.send(@progress, *(args + [val])) } end end |
#raw ⇒ Object
18 19 20 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 18 def raw @unparsed end |
#watermark? ⇒ Boolean
50 51 52 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 50 def watermark? @format_options[:watermark].present? end |
#watermark_params ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 54 def watermark_params return nil 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 positioning = case position when 'bottom_left' "#{margin}:main_h-overlay_h-#{margin}" when 'bottom_right' "main_w-overlay_w-#{margin}:main_h-overlay_h-#{margin}" when 'top_left' "#{margin}:#{margin}" when 'top_right' "main_w-overlay_w-#{margin}:#{margin}" end "-vf \"movie=#{path} [logo]; [in][logo] overlay=#{positioning} [out]\"" end end |