class Stratosphere::Video

Attributes

default[RW]
styles[RW]

Public Class Methods

new(owner, name, options={}) click to toggle source
Calls superclass method Stratosphere::Attachment::new
# File lib/stratosphere/video.rb, line 5
def initialize(owner, name, options={})
  super
  @type    = :video
  @styles  = []
  @default = options[:default]
  if @file_name && options[:styles] && options[:styles].count > 0
    options[:styles].each { |style| @styles.push Stratosphere::Style.new( style.merge(file_name: @file_name) ) }
  end
end

Public Instance Methods

encode() click to toggle source
# File lib/stratosphere/video.rb, line 37
def encode
  if styles.map { |s| s.format.nil? ? nil : s }.compact.count > 0
    options = {
        pipeline_id: config.aws[:transcoder][:pipeline],
        input: {
            key: "#{base_path}/original/#{file_name}",
            frame_rate: 'auto',
            resolution: 'auto',
            aspect_ratio: 'auto',
            interlaced: 'auto',
            container: 'auto'
        },
        outputs: []
    }
    styles.each_with_index do |s, i|
      unless s.format.nil? || s.name == :thumb
        k = "#{base_path}/#{s.format.to_s}/#{file_name.gsub("#{File.extname(file_name)}", '')}.#{s.format.to_s}"
        p = config.aws[:transcoder][:formats][s.format]
        t = i == 1 ? "#{base_path}/thumb/#{file_name.gsub("#{File.extname(file_name)}", '')}-{count}" : ''
        options[:outputs].push({ key: k, preset_id: p, thumbnail_pattern: t, rotate: '0' })
      end
    end
    Stratosphere::AWS::ElasticTranscoder.create_job(options)
  end
end
has_default?() click to toggle source
# File lib/stratosphere/video.rb, line 27
def has_default?
  !default.nil?
end
presigned_upload(options) click to toggle source
# File lib/stratosphere/video.rb, line 31
def presigned_upload(options)
  options.merge!(key: "#{base_path}/original/#{options[:file_name]}")
  options.delete :file_name
  file_store.presigned_upload options
end
url(style_name=:original) click to toggle source
# File lib/stratosphere/video.rb, line 15
def url(style_name=:original)
  url = default ? "#{config.domain}/#{default}" : nil
  if file_name
    url = "#{config.domain}/#{base_path}/#{style_name.to_s}/#{file_name}"
    unless style_name == :original
      style = styles.count > 0 ? self.styles.select { |style| style.name == style_name }.first : nil
      url.gsub!(file_name, style.file_name) unless style.nil?
    end
  end
  url
end