class MovieMasher::Input

An element in MovieMasher::Job#inputs representing media to be included in the mashup,which is eventually rendered into each Output format and uploaded. Inputsare generally combined together in the order they appear, though audio canbe mixed by specifying start times.

There are four types of inputs: Type::AUDIO, Type::IMAGE and Type::VIDEO(the three raw types) plus Type::MASH, which allows a Mash to be includedlike normal audio/video. Mashes can be generated in a web browser utilizingmoviemasher.js orangular-moviemasher can include raw elements composited on multiple tracks along withtitling, effects and transformations over time.

Relevant keys depend on type, though all inputs have av, source and#length keys. After downloading, relevant inputs are probed and will havetheir duration set if it's not already. The no_audio or no_video keysmight change to, as well as av which relies on them (for instance, fromAV::BOTH to AV::VIDEO_ONLY for a video that is found to contain no audiotrack).

Input.create(
  type: Type::VIDEO,
  source: 'video.mp4',
  fill: 'crop',        # remove pixels outside output's aspect ratio
  gain: 0.8,           # reduce volume by 20%
  offset: 10,          # remove first ten seconds
  length: 50,          # remove everything after the first minute
)

Public Class Methods

__copy_raw_from_media(clip, mash) click to toggle source
# File lib/input.rb, line 106
def self.__copy_raw_from_media(clip, mash)
  if Type::RAW_VISUALS.include?(clip[:type])
    media = Mash.media(mash, clip[:id])
    raise(Error::JobInput, "couldn't find media #{clip[:id]}") unless media
    # media props were copied to clip BEFORE file was cached, so do now
    clip[:cached_file] = media[:cached_file]
    raise("no cached_file #{media}") unless clip[:cached_file]
    clip[:no_video] ||= media[:no_video]
    clip[:dimensions] = media[:dimensions]
    raise("couldn't find dimensions #{media}") unless clip[:dimensions]
  end
end
__mash_range_graph(input, mash, range, job) click to toggle source
# File lib/input.rb, line 118
def self.__mash_range_graph(input, mash, range, job)
  graph = GraphMash.new(job, input, range)
  clips = Mash.clips_in_range(mash, range, Type::VIDEO)
  transition_layer = nil
  trans_clips = []
  clips.each do |clip|
    __copy_raw_from_media(clip, mash)
    if Type::TRANSITION == clip[:type]
      raise(Error::JobInput, "two transitions #{range}") if transition_layer
      transition_layer = graph.add_new_layer(clip)
    elsif clip[:track].zero?
      trans_clips << clip
    end
  end
  if transition_layer
    raise(Error::JobInput, "too many in #{range}") if 2 < trans_clips.length
    trans_clips.each do |clip|
      transition_layer.add_new_layer(clip)
    end
  end
  clips.each do |clip|
    next if transition_layer && clip[:track].zero?
    next unless Type::VISUALS.include?(clip[:type])
    graph.add_new_layer(clip)
  end
  graph
end
audio_graphs(inputs) click to toggle source
# File lib/input.rb, line 33
def self.audio_graphs(inputs)
  graphs = []
  inputs.each do |input|
    next if input[:no_audio]
    case input[:type]
    when Type::VIDEO, Type::AUDIO
      data = {}
      data[:type] = input[:type]
      data[:offset] = input[:offset]
      data[:length] = input[:length]
      data[:start] = input[:start]
      data[:cached_file] = input[:cached_file]
      data[:duration] = input[:duration]
      data[:gain] = input[:gain]
      data[:loop] = input[:loop]
      graphs << data
    when Type::MASH
      quantize = input[:mash][:quantize]
      audio_clips = Mash.clips_having_audio(input[:mash])
      audio_clips.each do |clip|
        media = Mash.media(input[:mash], clip[:id])
        unless media
          raise(Error::JobInput, "couldn't find media #{clip[:id]}")
        end
        next if clip[:no_audio] ||= media[:no_audio]
        raise('could not find cached file') unless media[:cached_file]
        data = {}
        data[:type] = clip[:type]
        data[:offset] = clip[:offset]
        data[:length] = clip[:length]
        data[:start] = input[:start].to_f
        data[:start] += clip[:frame].to_f / quantize.to_f
        data[:cached_file] = media[:cached_file]
        data[:gain] = clip[:gain]
        data[:duration] = media[:duration]
        data[:loop] = clip[:loop]
        graphs << data
      end
    end
  end
  graphs
end
create(hash = nil) click to toggle source

Returns a new instance.

# File lib/input.rb, line 76
def self.create(hash = nil)
  (hash.is_a?(Input) ? hash : Input.new(hash))
end
init_hash(input) click to toggle source
# File lib/input.rb, line 79
def self.init_hash(input)
  _init_time(input, :offset)
  Hashable._init_key(input, :start, FloatUtil::NEG_ONE)
  Hashable._init_key(input, :duration, FloatUtil::ZERO)
  Hashable._init_key(input, :length, 1.0) if Type::IMAGE == input[:type]
  _init_time(input, :length) # ^ image will be one by default, others zero
  input[:base_source] = Transfer.create_if(input[:base_source])
  input[:module_source] = Transfer.create_if(input[:module_source])
  Mash.init_input(input)
  input
end
new(hash = nil) click to toggle source
Calls superclass method
# File lib/input.rb, line 161
def initialize(hash = nil)
  # puts "Input#initialize #{hash}"
  self.class.init_hash hash
  super
end
video_graphs(inputs, job) click to toggle source
# File lib/input.rb, line 90
def self.video_graphs(inputs, job)
  graphs = []
  inputs.each do |input|
    next if input[:no_video]
    case input[:type]
    when Type::MASH
      mash = input[:mash]
      Mash.video_ranges(mash).each do |range|
        graphs << __mash_range_graph(input, mash, range, job)
      end
    when Type::VIDEO, Type::IMAGE
      graphs << GraphRaw.new(input)
    end
  end
  graphs
end

Public Instance Methods

base_source() click to toggle source
Transfer

Resolves relative URLs.

Default

MovieMasher::Job#base_source

Types

Just Type::MASH.

# File lib/input.rb, line 148
def base_source
  _get(__method__)
end
fill() click to toggle source
# File lib/input.rb, line 151
def fill
  _get(__method__)
end
fill=(value) click to toggle source
String

How to size in relation to MovieMasher::Output#dimensions.

Constant

Fill::CROP, Fill::NONE, Fill::SCALE or Fill::STRETCH.

Default

Fill::STRETCH.

Types

Type::IMAGE and Type::VIDEO.

# File lib/input.rb, line 158
def fill=(value)
  _set __method__, value
end
length() click to toggle source
# File lib/input.rb, line 166
def length
  _get(__method__)
end
length=(value) click to toggle source
Float

Seconds the input appears in the mashup.

Default

duration - offset

# File lib/input.rb, line 171
def length=(value)
  _set __method__, value
end
mash() click to toggle source
# File lib/input.rb, line 174
def mash
  _get(__method__)
end
mash=(value) click to toggle source
Mash

The mash to include in rendering.

Default

nil

Types

Just Type::MASH.

# File lib/input.rb, line 180
def mash=(value)
  _set __method__, value
end
module_source() click to toggle source
Transfer

Resolves relative font URLs for modules.

Default

MovieMasher::Job#module_source

Types

Just Type::MASH.

# File lib/input.rb, line 186
def module_source
  _get(__method__)
end
offset() click to toggle source
# File lib/input.rb, line 189
def offset
  _get(__method__)
end
offset=(value) click to toggle source
Float

Seconds to remove from beginning of input.

Default

0.0 means nothing removed.

Types

Type::AUDIO and Type::VIDEO.

# File lib/input.rb, line 195
def offset=(value)
  _set __method__, value
end
preflight(job = nil) click to toggle source
Calls superclass method MovieMasher::Asset#preflight
# File lib/input.rb, line 198
def preflight(job = nil)
  super
  mash.preflight job if mash
end
start() click to toggle source
# File lib/input.rb, line 202
def start
  _get(__method__)
end
start=(value) click to toggle source
Float

Seconds from start of mashup to introduce the input.

Default

-1.0 means after previous audio in mashup completes.

Types

Just Type::AUDIO.

# File lib/input.rb, line 208
def start=(value)
  _set __method__, value
end