class MovieMasher::Input

An element in Job#inputs representing media to be included in the mashup, which is eventually rendered into each Output format and uploaded. Inputs are generally combined together in the order they appear, though audio can be 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 included like normal audio/video. Mashes can be generated in a web browser utilizing moviemasher.js or angular-moviemasher and can include raw elements composited on multiple tracks along with titling, 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 have their duration set if it's not already. The no_audio or no_video keys might change to, as well as av which relies on them (for instance, from AV::BOTH to AV::VIDEO_ONLY for a video that is found to contain no audio track).

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
)

Constants

KEYS_AV_GRAPH

Public Class Methods

audio_graphs(inputs) click to toggle source
# File lib/input.rb, line 38
def audio_graphs(inputs)
  graphs = []
  inputs.each do |input|
    next if input[:no_audio]

    case input[:type]
    when Type::VIDEO, Type::AUDIO
      graph = input.slice(*KEYS_AV_GRAPH)
      graph[:start] = input[:start]
      graphs << graph
    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]

        graph = clip.slice(*KEYS_AV_GRAPH)
        graph[:start] = input[:start].to_f
        graph[:start] += (clip[:frame].to_f / quantize)
        graph[:cached_file] = media[:cached_file]
        graph[:duration] = media[:duration]
        graphs << graph
      end
    end
  end
  graphs
end
create(hash = nil) click to toggle source

Returns

Returns a new instance.

# File lib/input.rb, line 72
def create(hash = nil)
  (hash.is_a?(Input) ? hash : Input.new(hash))
end
init_hash(input) click to toggle source
# File lib/input.rb, line 76
def 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 186
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 88
def 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

Job#base_source

Types

Just Type::MASH.

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

How to size in relation to 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 182
def fill=(value)
  _set __method__, value
end
length() click to toggle source
# File lib/input.rb, line 192
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 198
def length=(value)
  _set __method__, value
end
mash() click to toggle source
# File lib/input.rb, line 202
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 209
def mash=(value)
  _set __method__, value
end
module_source() click to toggle source
Transfer

Resolves relative font URLs for modules.

Default

Job#module_source

Types

Just Type::MASH.

# File lib/input.rb, line 216
def module_source
  _get(__method__)
end
offset() click to toggle source
# File lib/input.rb, line 220
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 227
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 231
def preflight(job = nil)
  super
  mash&.preflight job
end
start() click to toggle source
# File lib/input.rb, line 236
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 243
def start=(value)
  _set __method__, value
end