Class: Ffmprb::Process::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/ffmprb/process/input.rb

Direct Known Subclasses

Cropped, Cut, Loud

Defined Under Namespace

Classes: Cropped, Cut, Loud

Instance Method Summary collapse

Constructor Details

#initialize(io, only: nil) ⇒ Input

Returns a new instance of Input.

Raises:



107
108
109
110
111
112
113
114
# File 'lib/ffmprb/process/input.rb', line 107

def initialize(io, only: nil)
  @io = io
  @channels = [*only]
  @channels = nil  if @channels.empty?
  raise Error, "Inadequate A/V channels"  if
    @io.respond_to?(:channel?) &&
      [:video, :audio].any?{|medium| !@io.channel?(medium) && channel?(medium, true)}
end

Instance Method Details

#audioObject



149
150
151
# File 'lib/ffmprb/process/input.rb', line 149

def audio
  Input.new self, only: :audio
end

#channel?(medium, force = false) ⇒ Boolean

XXX? protected

Returns:

  • (Boolean)


167
168
169
170
171
172
# File 'lib/ffmprb/process/input.rb', line 167

def channel?(medium, force=false)
  return @channels && @channels.include?(medium)  if force

  (!@channels || @channels.include?(medium)) &&
    (!@io.respond_to?(:channel?) || @io.channel?(medium))
end

#crop(ratio) ⇒ Object

NOTE ratio is either a CROP_PARAMS symbol-ratio hash or a single (global) ratio



153
154
155
# File 'lib/ffmprb/process/input.rb', line 153

def crop(ratio)  # NOTE ratio is either a CROP_PARAMS symbol-ratio hash or a single (global) ratio
  Cropped.new self, crop: ratio
end

#cut(from: 0, to: nil) ⇒ Object



157
158
159
# File 'lib/ffmprb/process/input.rb', line 157

def cut(from: 0, to: nil)
  Cut.new self, from: from, to: to
end

#filters_for(lbl, process:, video: true, audio: true) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ffmprb/process/input.rb', line 120

def filters_for(lbl, process:, video: true, audio: true)

  # Channelling

  if @io.respond_to?(:filters_for)  # NOTE assuming @io.respond_to?(:channel?)
    lbl_aux = "au#{lbl}"
    @io.filters_for(lbl_aux, process: process, video: video, audio: audio) +
      [
        *((video && @io.channel?(:video))?
          (channel?(:video)? Filter.copy("#{lbl_aux}:v", "#{lbl}:v"): Filter.nullsink("#{lbl_aux}:v")):
          nil),
        *((audio && @io.channel?(:audio))?
          (channel?(:audio)? Filter.anull("#{lbl_aux}:a", "#{lbl}:a"): Filter.anullsink("#{lbl_aux}:a")):
          nil)
      ]
  else
    in_lbl = process[self]
    raise Error, "Data corruption"  unless in_lbl
    [
      *(video && channel?(:video)? Filter.copy("#{in_lbl}:v", "#{lbl}:v"): nil),
      *(audio && channel?(:audio)? Filter.anull("#{in_lbl}:a", "#{lbl}:a"): nil)
    ]
  end
end

#optionsObject



116
117
118
# File 'lib/ffmprb/process/input.rb', line 116

def options
  " -i #{@io.path}"
end

#videoObject



145
146
147
# File 'lib/ffmprb/process/input.rb', line 145

def video
  Input.new self, only: :video
end

#volume(vol) ⇒ Object



161
162
163
# File 'lib/ffmprb/process/input.rb', line 161

def volume(vol)
  Loud.new self, volume: vol
end