Class: Ffmprb::Process::Input
- Inherits:
-
Object
- Object
- Ffmprb::Process::Input
- Defined in:
- lib/ffmprb/process/input.rb,
lib/ffmprb/process/input/cut.rb,
lib/ffmprb/process/input/loud.rb,
lib/ffmprb/process/input/temp.rb,
lib/ffmprb/process/input/cropped.rb,
lib/ffmprb/process/input/looping.rb,
lib/ffmprb/process/input/channeled.rb,
lib/ffmprb/process/input/chain_base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ChainBase, Channeled, Cropped, Cut, Looping, Loud
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Class Method Summary collapse
- .audio_args(audio = nil) ⇒ Object
- .resolve(io) ⇒ Object
-
.video_args(video = nil) ⇒ Object
TODO! check for unknown options.
Instance Method Summary collapse
- #args ⇒ Object
- #audio ⇒ Object
- #chain_copy(src_input) ⇒ Object
- #channel(medium) ⇒ Object
- #channel?(medium) ⇒ Boolean
- #copy(input) ⇒ Object
-
#crop(ratio) ⇒ Object
NOTE ratio is either a CROP_PARAMS symbol-ratio hash or a single (global) ratio.
- #cut(from: 0, to: nil) ⇒ Object
- #filters_for(lbl, video:, audio:) ⇒ Object
-
#initialize(io, process, video:, audio:) ⇒ Input
constructor
A new instance of Input.
- #loop(times = Util.ffmpeg_inputs_max) ⇒ Object
- #mute ⇒ Object
- #temporise_io!(extname = nil) ⇒ Object
- #video ⇒ Object
- #volume(vol) ⇒ Object
Constructor Details
#initialize(io, process, video:, audio:) ⇒ Input
Returns a new instance of Input.
41 42 43 44 45 46 47 48 |
# File 'lib/ffmprb/process/input.rb', line 41 def initialize(io, process, video:, audio:) @io = self.class.resolve(io) @process = process @channels = { video: video && @io.channel?(:video) && OpenStruct.new(video), audio: audio && @io.channel?(:audio) && OpenStruct.new(audio) } end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
38 39 40 |
# File 'lib/ffmprb/process/input.rb', line 38 def io @io end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
39 40 41 |
# File 'lib/ffmprb/process/input.rb', line 39 def process @process end |
Class Method Details
.audio_args(audio = nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ffmprb/process/input.rb', line 29 def audio_args(audio=nil) audio = Process..merge(audio.to_h) [].tap do |args| Util. audio end end |
.resolve(io) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ffmprb/process/input.rb', line 9 def resolve(io) return io unless io.is_a? String # XXX XXX File.open(io).tap do |file| Ffmprb.logger.warn "Input file does no exist (#{file.path}), will probably fail" unless file.exist? end end |
.video_args(video = nil) ⇒ Object
TODO! check for unknown options
19 20 21 22 23 24 25 26 27 |
# File 'lib/ffmprb/process/input.rb', line 19 def video_args(video=nil) video = Process..merge(video.to_h) [].tap do |args| fps = nil # NOTE ah, ruby args.concat %W[-noautorotate] unless video.delete(:auto_rotate) args.concat %W[-r #{fps}] if (fps = video.delete(:fps)) Util. video end end |
Instance Method Details
#args ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ffmprb/process/input.rb', line 56 def args [].tap do |args| args.concat self.class.video_args(channel :video) if channel? :video args.concat self.class.audio_args(channel :audio) if channel? :audio args.concat ['-i', io.path] end end |
#audio ⇒ Object
11 12 13 |
# File 'lib/ffmprb/process/input/channeled.rb', line 11 def audio Channeled.new self, video: false end |
#chain_copy(src_input) ⇒ Object
97 98 99 |
# File 'lib/ffmprb/process/input.rb', line 97 def chain_copy(src_input) src_input end |
#channel(medium) ⇒ Object
92 93 94 |
# File 'lib/ffmprb/process/input.rb', line 92 def channel(medium) @channels[medium] end |
#channel?(medium) ⇒ Boolean
88 89 90 |
# File 'lib/ffmprb/process/input.rb', line 88 def channel?(medium) io.channel? medium end |
#copy(input) ⇒ Object
51 52 53 |
# File 'lib/ffmprb/process/input.rb', line 51 def copy(input) input.chain_copy self end |
#crop(ratio) ⇒ Object
NOTE ratio is either a CROP_PARAMS symbol-ratio hash or a single (global) ratio
7 8 9 |
# File 'lib/ffmprb/process/input/cropped.rb', line 7 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
7 8 9 |
# File 'lib/ffmprb/process/input/cut.rb', line 7 def cut(from: 0, to: nil) Cut.new self, from: from, to: to end |
#filters_for(lbl, video:, audio:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ffmprb/process/input.rb', line 64 def filters_for(lbl, video:, audio:) in_lbl = process.input_label(self) [ *(if video && channel?(:video) if video.resolution && video.fps Filter.scale_pad_fps video.resolution, video.fps, "#{in_lbl}:v", "#{lbl}:v" elsif video.resolution Filter.scale_pad video.resolution, "#{in_lbl}:v", "#{lbl}:v" elsif video.fps Filter.fps video.fps, "#{in_lbl}:v", "#{lbl}:v" else Filter.copy "#{in_lbl}:v", "#{lbl}:v" end elsif video fail Error, "No video stream to provide" end), *(if audio && channel?(:audio) Filter.anull "#{in_lbl}:a", "#{lbl}:a" elsif audio fail Error, "No audio stream to provide" end) ] end |
#loop(times = Util.ffmpeg_inputs_max) ⇒ Object
7 8 9 10 |
# File 'lib/ffmprb/process/input/looping.rb', line 7 def loop(times=Util.ffmpeg_inputs_max) Ffmprb.logger.warn "Looping more than #{Util.ffmpeg_inputs_max} times is 'unstable': either use double looping or ask for this feature" if times > Util.ffmpeg_inputs_max Looping.new self, times end |
#mute ⇒ Object
7 8 9 |
# File 'lib/ffmprb/process/input/loud.rb', line 7 def mute Loud.new self, volume: 0 end |
#temporise_io!(extname = nil) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ffmprb/process/input/temp.rb', line 7 def temporise_io!(extname=nil) process.proc_vis_edge @io, process, :remove @io.tap do @io = File.temp_fifo(extname || io.extname) process.proc_vis_edge @io, process end end |
#video ⇒ Object
7 8 9 |
# File 'lib/ffmprb/process/input/channeled.rb', line 7 def video Channeled.new self, audio: false end |
#volume(vol) ⇒ Object
11 12 13 |
# File 'lib/ffmprb/process/input/loud.rb', line 11 def volume(vol) Loud.new self, volume: vol end |