Class: CarrierWave::Video::FfmpegOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/video/ffmpeg_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @format = format.to_s
  @resolution = options[:resolution] || "640x360"
  @custom = options[:custom]
  @callbacks = options[:callbacks] || {}
  @logger = options[:logger]
  @unparsed = options
  @progress = options[:progress]

  @format_options = defaults.merge(options)
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



4
5
6
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4

def callbacks
  @callbacks
end

#customObject (readonly)

Returns the value of attribute custom.



4
5
6
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4

def custom
  @custom
end

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 4

def format
  @format
end

#resolutionObject (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_optionsObject



33
34
35
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 33

def encoder_options
  { preserve_aspect_ratio: :width }
end

#format_optionsObject

input



38
39
40
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 38

def format_options
  @format_options
end

#format_paramsObject

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

#rawObject



18
19
20
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 18

def raw
  @unparsed
end

#watermark?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/carrierwave/video/ffmpeg_options.rb', line 50

def watermark?
  @format_options[:watermark].present?
end

#watermark_paramsObject



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