Class: Bulldog::Processor::Ffmpeg

Inherits:
Base
  • Object
show all
Defined in:
lib/bulldog/processor/ffmpeg.rb

Class Attribute Summary collapse

Attributes inherited from Base

#attachment, #input_file, #style, #styles

Instance Method Summary collapse

Methods inherited from Base

#name, #output_file, #record, #value

Constructor Details

#initialize(*args) ⇒ Ffmpeg

Returns a new instance of Ffmpeg.



8
9
10
# File 'lib/bulldog/processor/ffmpeg.rb', line 8

def initialize(*args)
  super
end

Class Attribute Details

.ffmpeg_pathObject

Returns the value of attribute ffmpeg_path.



5
6
7
# File 'lib/bulldog/processor/ffmpeg.rb', line 5

def ffmpeg_path
  @ffmpeg_path
end

Instance Method Details

#encode(params = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bulldog/processor/ffmpeg.rb', line 31

def encode(params={})
  @operation = :encode
  params = style.attributes.merge(params)
  parse_video_option(params)
  parse_audio_option(params)
  style_option '-vcodec', params[:video_codec]
  style_option '-acodec', params[:audio_codec]
  preset_option '-vpre', params[:video_preset]
  preset_option '-apre', params[:audio_preset]
  preset_option '-spre', params[:subtitle_preset]
  operate '-s', attachment.dimensions(style.name).join('x') if params[:size]
  style_option '-r', params[:frame_rate]
  style_option '-b', params[:video_bit_rate]
  style_option '-ar', params[:sampling_rate]
  style_option '-ab', params[:audio_bit_rate]
  style_option '-ac', params[:channels]
  operate '-deinterlace' if params[:deinterlaced]
  style_option '-pix_fmt', params[:pixel_format]
  style_option '-b_strategy', params[:b_strategy]
  style_option '-bufsize', params[:buffer_size]
  style_option '-coder', params[:coder]
  style_option '-v', params[:verbosity]
  style_option '-flags', params[:flags]
  style_option '-y', output_file(style.name)
end

#process(styles, options = {}) ⇒ Object



12
13
14
15
# File 'lib/bulldog/processor/ffmpeg.rb', line 12

def process(styles, options={})
  super or
    return
end

#process_style(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bulldog/processor/ffmpeg.rb', line 17

def process_style(*args)
  @operation = nil
  @arguments = []
  @still_frame_callbacks = []
  super
  set_default_operation
  run_ffmpeg
  run_still_frame_callbacks
end

#record_frame(params = {}, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bulldog/processor/ffmpeg.rb', line 57

def record_frame(params={}, &block)
  @operation = :record_frame
  params = style.attributes.merge(params)
  operate '-vframes', 1
  operate '-ss', params[:position] || attachment.duration.to_i / 2
  operate '-f', 'image2'
  operate '-vcodec', params[:codec] || default_frame_codec(params)

  if (attribute = params[:assign_to])
    basename = "recorded_frame.#{params[:format]}"
    output_path = record.send(attribute).interpolate_path(:original, :basename => basename)
    @still_frame_callbacks << lambda do
      if existing_frame_path(attribute) == output_path
        attachment.reload
      else
        file = SavedFile.new(output_path, :file_name => basename)
        record.update_attribute(attribute, file)
      end
    end
  else
    output_path = output_file(style.name)
  end

  FileUtils.mkdir_p File.dirname(output_path)
  operate '-y', output_path
  if block
    @still_frame_callbacks << lambda{instance_exec(output_path, &block)}
  end
end

#use_threads(num_threads) ⇒ Object



27
28
29
# File 'lib/bulldog/processor/ffmpeg.rb', line 27

def use_threads(num_threads)
  operate '-threads', num_threads
end