class MovieMasher::Mash
Input#source
of mash inputs, representing a collection media
arranged on audio
and video
tracks.
Public Class Methods
audio?(mash)
click to toggle source
# File lib/mash.rb, line 85 def audio?(mash) Type::TRACKS.each do |track_type| mash[track_type.to_sym].each do |track| track[:clips].each do |clip| return true if clip_has_audio(clip) end end end false end
clip_has_audio(clip)
click to toggle source
# File lib/mash.rb, line 8 def clip_has_audio(clip) has = false unless clip[:no_audio] url = case clip[:type] when Type::AUDIO clip[:source] || clip[:audio] when Type::VIDEO clip[:source] || __nonzero_audio(clip) end if url has = !clip[:gain] has ||= !__gain_mutes(clip[:gain]) end end has end
clips_having_audio(mash)
click to toggle source
# File lib/mash.rb, line 26 def clips_having_audio(mash) clips = [] Type::TRACKS.each do |track_type| mash[track_type.to_sym].each do |track| track[:clips].each do |clip| clips << clip if clip_has_audio(clip) end end end clips end
clips_in_range(mash, range, track_type)
click to toggle source
# File lib/mash.rb, line 38 def clips_in_range(mash, range, track_type) clips_in_range = [] mash[track_type.to_sym].each do |track| track[:clips].each do |clip| clips_in_range << clip if range.intersection(clip[:range]) end end clips_in_range.sort do |a, b| if a[:track] == b[:track] a[:frame] <=> b[:frame] else a[:track] <=> b[:track] end end end
duration(mash)
click to toggle source
# File lib/mash.rb, line 54 def duration(mash) mash[:length] / mash[:quantize] end
gain_changes(gain)
click to toggle source
# File lib/mash.rb, line 58 def gain_changes(gain) does = false if gain.is_a?(String) && gain.include?(',') gains = gain.split ',' (gains.length / 2).times do |i| does = !FloatUtil.cmp(gains[1 + i * 2].to_f, Gain::None) break if does end else does = !FloatUtil.cmp(gain.to_f, Gain::None) end does end
hash?(hash)
click to toggle source
# File lib/mash.rb, line 72 def hash?(hash) isa = false if hash.is_a?(Hash) || hash.is_a?(Mash) medias = __ob_prop(:media, hash) if medias.is_a?(Array) video_tracks = __ob_prop(:video, hash) audio_tracks = __ob_prop(:audio, hash) isa = (video_tracks || audio_tracks) end end isa end
init_av_input(input)
click to toggle source
# File lib/mash.rb, line 132 def init_av_input(input) if input[:no_video] (input[:no_audio] ? AV::NEITHER : AV::AUDIO_ONLY) else (input[:no_audio] ? AV::VIDEO_ONLY : AV::BOTH) end end
init_hash(mash)
click to toggle source
# File lib/mash.rb, line 102 def init_hash(mash) Hashable._init_key mash, :backcolor, 'black' mash[:quantize] ||= FloatUtil::ONE mash[:quantize] = mash[:quantize].to_f mash[:media] ||= [] longest = FloatUtil::ZERO Type::TRACKS.each do |track_type| track_sym = track_type.to_sym mash[track_sym] ||= [] mash[track_sym].length.times do |track_index| track = mash[track_sym][track_index] track[:clips] ||= [] track[:clips].map! do |clip| clip = __init_clip clip, mash, track_index, track_type __init_clip_media(clip[:merger], mash, :merger) __init_clip_media(clip[:scaler], mash, :scaler) clip[:effects].each do |effect| __init_clip_media(effect, mash, :effect) end clip end clip = track[:clips].last longest = FloatUtil.max(longest, clip[:range].stop) if clip track_index += 1 end end mash[:length] = longest mash end
init_input(input)
click to toggle source
# File lib/mash.rb, line 140 def init_input(input) input[:effects] ||= [] input[:merger] ||= Defaults.module_for_type(:merger) input[:scaler] ||= Defaults.module_for_type(:scaler) unless input[:fill] __init_input_av(input) __init_input_fill(input) __init_input_source(input) end
init_mash_input(input)
click to toggle source
# File lib/mash.rb, line 149 def init_mash_input(input) return unless hash?(input[:mash]) input[:mash] = Mash.new(input[:mash]) input[:mash]&.preflight if FloatUtil.cmp(input[:duration], FloatUtil::ZERO) input[:duration] = duration(input[:mash]) end input[:no_audio] = !audio?(input[:mash]) input[:no_video] = !video?(input[:mash]) end
media(mash, ob_or_id)
click to toggle source
# File lib/mash.rb, line 161 def media(mash, ob_or_id) return nil unless mash && ob_or_id ob_or_id = __ob_prop(:id, ob_or_id) if ob_or_id.is_a?(Hash) if ob_or_id media_array = __ob_prop(:media, mash) if media_array.is_a?(Array) media_array.each do |media| id = __ob_prop(:id, media) return media if id == ob_or_id end end end nil end
media_count_for_clips(mash, clips, referenced)
click to toggle source
# File lib/mash.rb, line 177 def media_count_for_clips(mash, clips, referenced) referenced ||= {} clips&.each do |clip| media_id = __ob_prop(:id, clip) __media_reference(mash, media_id, referenced) reference = referenced[media_id] raise("__media_reference with no #{media_id}") unless reference media = reference[:media] next unless media if __modular_media?(media) keys = __properties_for_media(media, Type::FONT) keys.each do |key| font_id = clip[key] __media_reference(mash, font_id, referenced, Type::FONT) end end media_type = __ob_prop(:type, media) case media_type when Type::TRANSITION __media_merger_scaler(mash, __ob_prop(:to, media), referenced) __media_merger_scaler(mash, __ob_prop(:from, media), referenced) when Type::EFFECT, Type::AUDIO # do nothing since clip has no effects, merger or scaler else __media_merger_scaler(mash, clip, referenced) effects = __ob_prop(:effects, clip) media_count_for_clips(mash, effects, referenced) end end end
media_search(type, ob_or_id, mash)
click to toggle source
# File lib/mash.rb, line 210 def media_search(type, ob_or_id, mash) return unless ob_or_id media_ob = nil ob_or_id = __ob_prop(:id, ob_or_id) if ob_or_id.is_a?(Hash) if ob_or_id media_ob = media(mash, ob_or_id) if mash media_ob ||= Defaults.module_for_type(type, ob_or_id) end media_ob end
new(hash)
click to toggle source
Calls superclass method
# File lib/mash.rb, line 465 def initialize(hash) super self.class.init_hash(@hash) end
video?(mash)
click to toggle source
# File lib/mash.rb, line 96 def video?(mash) mash && mash[:video] && mash[:video].any? do |track| track[:clips]&.any? end end
video_ranges(mash)
click to toggle source
# File lib/mash.rb, line 222 def video_ranges(mash) quantize = mash[:quantize] frames = [] frames << 0 frames << mash[:length] mash[:video].each do |track| track[:clips].each do |clip| frames << clip[:range].start frames << clip[:range].stop end end all_ranges = [] frames.uniq! frames.sort! frame = nil frames.length.times do |i| if frame all_ranges << TimeRange.new(frame, quantize, frames[i] - frame) end frame = frames[i] end all_ranges end
Public Instance Methods
audio()
click to toggle source
- Array
-
One or more Track objects.
# File lib/mash.rb, line 461 def audio _get(__method__) end
media()
click to toggle source
- Array
-
One or more Media objects.
# File lib/mash.rb, line 471 def media _get(__method__) end
preflight(job = nil)
click to toggle source
# File lib/mash.rb, line 475 def preflight(job = nil) media.map! do |media| case media[:type] when Type::VIDEO, Type::AUDIO, Type::IMAGE, Type::FRAME, Type::FONT media = Clip.create media media.preflight job end media end end
url_count(desired)
click to toggle source
# File lib/mash.rb, line 486 def url_count(desired) count = 0 media.each do |media| case media[:type] when Type::VIDEO, Type::AUDIO, Type::IMAGE, Type::FONT count += 1 if AV.includes?(Asset.av_type(media), desired) end end count end
video()
click to toggle source
- Array
-
One or more Track objects.
# File lib/mash.rb, line 498 def video _get(__method__) end