Class: Ffmprb::Process::Input::Cut

Inherits:
ChainBase show all
Defined in:
lib/ffmprb/process/input/cut.rb

Instance Attribute Summary collapse

Attributes inherited from Ffmprb::Process::Input

#io, #process

Instance Method Summary collapse

Methods inherited from ChainBase

#chain_copy, #channel, #unfiltered, #unfiltered=

Methods inherited from Ffmprb::Process::Input

#args, #audio, audio_args, #chain_copy, #channel, #channel?, #copy, #crop, #cut, #loop, #mute, #pace, #pp, resolve, #reverse, #temporise_io!, #video, video_args, #volume

Constructor Details

#initialize(unfiltered, from:, to:) ⇒ Cut

Returns a new instance of Cut.



15
16
17
18
19
20
21
22
# File 'lib/ffmprb/process/input/cut.rb', line 15

def initialize(unfiltered, from:, to:)
  super unfiltered
  @from = from
  @to = to.to_f == 0 ? nil : to

  fail Error, "cut from: must be"  unless from
  fail Error, "cut from: must be less than to:"  unless !to || from < to
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



13
14
15
# File 'lib/ffmprb/process/input/cut.rb', line 13

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



13
14
15
# File 'lib/ffmprb/process/input/cut.rb', line 13

def to
  @to
end

Instance Method Details

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ffmprb/process/input/cut.rb', line 24

def filters_for(lbl, video:, audio:)
  fail Error, "cut needs resolution and fps (reorder your filters?)"  unless
    !video || (video.resolution && video.fps)

  # Trimming

  lbl_aux = "tm#{lbl}"
  super(lbl_aux, video: video, audio: audio) +
    if to
      lbl_blk = "bl#{lbl}"
      lbl_pad = "pd#{lbl}"
      [
        *((video && channel?(:video))?
          Filter.blank_source(to - from, video.resolution, video.fps, "#{lbl_blk}:v") +
          Filter.concat_v(["#{lbl_aux}:v", "#{lbl_blk}:v"], "#{lbl_pad}:v") +
          Filter.trim(from, to, "#{lbl_pad}:v", "#{lbl}:v")
          : nil),
        *((audio && channel?(:audio))?
          Filter.silent_source(to - from, "#{lbl_blk}:a") +
          Filter.concat_a(["#{lbl_aux}:a", "#{lbl_blk}:a"], "#{lbl_pad}:a") +
          Filter.atrim(from, to, "#{lbl_pad}:a", "#{lbl}:a")
          : nil)
      ]
    elsif from == 0
      [
        *((video && channel?(:video))? Filter.copy("#{lbl_aux}:v", "#{lbl}:v"): nil),
        *((audio && channel?(:audio))? Filter.anull("#{lbl_aux}:a", "#{lbl}:a"): nil)
      ]
    else  # !to
      [
        *((video && channel?(:video))? Filter.trim(from, nil, "#{lbl_aux}:v", "#{lbl}:v"): nil),
        *((audio && channel?(:audio))? Filter.atrim(from, nil, "#{lbl_aux}:a", "#{lbl}:a"): nil)
      ]
    end
end