Class: Paperclip::Qtfaststart

Inherits:
Processor
  • Object
show all
Defined in:
lib/paperclip_processors/qtfaststart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Qtfaststart

Creates a Video object set to work on the file given. It will attempt to reposition the moov atom in the video given if streaming is set.



8
9
10
11
12
13
14
15
16
# File 'lib/paperclip_processors/qtfaststart.rb', line 8

def initialize file, options = {}, attachment = nil
  @streaming      = options[:streaming]
  @file            = file
  @whiny           = options[:whiny].nil? ? true : options[:whiny]
  @format          = options[:format]
  @current_format  = File.extname(@file.path)
  @basename        = File.basename(@file.path, @current_format)
  attachment.instance_write(:meta, @meta)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/paperclip_processors/qtfaststart.rb', line 3

def format
  @format
end

#streamingObject

Returns the value of attribute streaming.



3
4
5
# File 'lib/paperclip_processors/qtfaststart.rb', line 3

def streaming
  @streaming
end

#whinyObject

Returns the value of attribute whiny.



3
4
5
# File 'lib/paperclip_processors/qtfaststart.rb', line 3

def whiny
  @whiny
end

Instance Method Details

#makeObject

Performs the atom repositioning on file. Returns the Tempfile that contains the new video or the original file if streaming wasn’t set.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/paperclip_processors/qtfaststart.rb', line 21

def make
  return @file unless @streaming
  
  src = @file
  dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
  dst.binmode
  
  parameters = []
  # Add source
  parameters << ":source"
  # Add destination
  parameters << ":dest"

  parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
  
  Paperclip.log("[qtfaststart] #{parameters}")
  begin
    success = Paperclip.run("qt-faststart", parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
  rescue Cocaine::ExitStatusError => e
    raise PaperclipError, "error while processing video for #{@basename}: #{e}" if @whiny
  end

  dst
end