Class: Ffmprb::Process
- Inherits:
-
Object
- Object
- Ffmprb::Process
- Defined in:
- lib/ffmprb/process.rb,
lib/ffmprb/process/input.rb,
lib/ffmprb/process/output.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
Defined Under Namespace
Class Attribute Summary collapse
-
.duck_audio_silent_min ⇒ Object
Returns the value of attribute duck_audio_silent_min.
-
.duck_audio_transition_in_start ⇒ Object
Returns the value of attribute duck_audio_transition_in_start.
-
.duck_audio_transition_length ⇒ Object
Returns the value of attribute duck_audio_transition_length.
-
.duck_audio_transition_out_start ⇒ Object
Returns the value of attribute duck_audio_transition_out_start.
-
.duck_audio_volume_hi ⇒ Object
Returns the value of attribute duck_audio_volume_hi.
-
.duck_audio_volume_lo ⇒ Object
Returns the value of attribute duck_audio_volume_lo.
-
.input_options ⇒ Object
Returns the value of attribute input_options.
-
.output_audio_encoder ⇒ Object
Returns the value of attribute output_audio_encoder.
-
.output_video_fps ⇒ Object
Returns the value of attribute output_video_fps.
-
.output_video_resolution ⇒ Object
Returns the value of attribute output_video_resolution.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Attribute Summary collapse
-
#ignore_broken_pipe ⇒ Object
Returns the value of attribute ignore_broken_pipe.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
-
.duck_audio(av_main_i, a_overlay_i, silence, av_main_o, volume_lo: duck_audio_volume_lo, volume_hi: duck_audio_volume_hi, silent_min: duck_audio_silent_min, process_options: {}, video:, audio:) ⇒ Object
NOTE Temporarily, av_main_i/o and not a_main_i/o.
- .intermediate_channel_extname(*media) ⇒ Object
- .output_audio_options ⇒ Object
- .output_video_options ⇒ Object
Instance Method Summary collapse
-
#initialize(*args, **opts) ⇒ Process
constructor
A new instance of Process.
- #input(io, **opts) ⇒ Object
- #input_label(input) ⇒ Object
- #output(io, video: true, audio: true, &blk) ⇒ Object
- #output_index(output) ⇒ Object
-
#run(limit: nil) ⇒ Object
NOTE the one and the only entry-point processing function which spawns threads etc.
-
#temp_input(extname) ⇒ Object
XXX SPEC ME.
Constructor Details
#initialize(*args, **opts) ⇒ Process
Returns a new instance of Process.
93 94 95 96 97 98 99 |
# File 'lib/ffmprb/process.rb', line 93 def initialize(*args, **opts) @inputs, @outputs = [], [] self.timeout = opts.delete(:timeout) || self.class.timeout self.ignore_broken_pipe = opts.delete(:ignore_broken_pipe) fail Error, "Unknown options: #{opts}" unless opts.empty? end |
Class Attribute Details
.duck_audio_silent_min ⇒ Object
Returns the value of attribute duck_audio_silent_min.
7 8 9 |
# File 'lib/ffmprb/process.rb', line 7 def duck_audio_silent_min @duck_audio_silent_min end |
.duck_audio_transition_in_start ⇒ Object
Returns the value of attribute duck_audio_transition_in_start.
9 10 11 |
# File 'lib/ffmprb/process.rb', line 9 def duck_audio_transition_in_start @duck_audio_transition_in_start end |
.duck_audio_transition_length ⇒ Object
Returns the value of attribute duck_audio_transition_length.
9 10 11 |
# File 'lib/ffmprb/process.rb', line 9 def duck_audio_transition_length @duck_audio_transition_length end |
.duck_audio_transition_out_start ⇒ Object
Returns the value of attribute duck_audio_transition_out_start.
9 10 11 |
# File 'lib/ffmprb/process.rb', line 9 def duck_audio_transition_out_start @duck_audio_transition_out_start end |
.duck_audio_volume_hi ⇒ Object
Returns the value of attribute duck_audio_volume_hi.
7 8 9 |
# File 'lib/ffmprb/process.rb', line 7 def duck_audio_volume_hi @duck_audio_volume_hi end |
.duck_audio_volume_lo ⇒ Object
Returns the value of attribute duck_audio_volume_lo.
7 8 9 |
# File 'lib/ffmprb/process.rb', line 7 def duck_audio_volume_lo @duck_audio_volume_lo end |
.input_options ⇒ Object
Returns the value of attribute input_options.
12 13 14 |
# File 'lib/ffmprb/process.rb', line 12 def @input_options end |
.output_audio_encoder ⇒ Object
Returns the value of attribute output_audio_encoder.
16 17 18 |
# File 'lib/ffmprb/process.rb', line 16 def output_audio_encoder @output_audio_encoder end |
.output_video_fps ⇒ Object
Returns the value of attribute output_video_fps.
15 16 17 |
# File 'lib/ffmprb/process.rb', line 15 def output_video_fps @output_video_fps end |
.output_video_resolution ⇒ Object
Returns the value of attribute output_video_resolution.
14 15 16 |
# File 'lib/ffmprb/process.rb', line 14 def output_video_resolution @output_video_resolution end |
.timeout ⇒ Object
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/ffmprb/process.rb', line 18 def timeout @timeout end |
Instance Attribute Details
#ignore_broken_pipe ⇒ Object
Returns the value of attribute ignore_broken_pipe.
91 92 93 |
# File 'lib/ffmprb/process.rb', line 91 def ignore_broken_pipe @ignore_broken_pipe end |
#timeout ⇒ Object
Returns the value of attribute timeout.
90 91 92 |
# File 'lib/ffmprb/process.rb', line 90 def timeout @timeout end |
Class Method Details
.duck_audio(av_main_i, a_overlay_i, silence, av_main_o, volume_lo: duck_audio_volume_lo, volume_hi: duck_audio_volume_hi, silent_min: duck_audio_silent_min, process_options: {}, video:, audio:) ⇒ Object
NOTE Temporarily, av_main_i/o and not a_main_i/o
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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.rb', line 45 def duck_audio(av_main_i, , silence, av_main_o, volume_lo: duck_audio_volume_lo, volume_hi: duck_audio_volume_hi, silent_min: duck_audio_silent_min, process_options: {}, video:, # NOTE Temporarily, video should not be here audio: ) Ffmprb.process ** do in_main = input(av_main_i) in_over = input() output(av_main_o, video: video, audio: audio) do roll in_main = {0.0 => volume_lo} silence.each do |silent| next if silent.end_at && silent.start_at && (silent.end_at - silent.start_at) < silent_min if silent.start_at transition_in_start = silent.start_at + Process.duck_audio_transition_in_start .merge!( [transition_in_start, 0.0].max => volume_lo, (transition_in_start + Process.duck_audio_transition_length) => volume_hi ) end if silent.end_at transition_out_start = silent.end_at + Process.duck_audio_transition_out_start .merge!( [transition_out_start, 0.0].max => volume_hi, (transition_out_start + Process.duck_audio_transition_length) => volume_lo ) end end in_over.volume Ffmprb.logger.debug "Ducking audio with volumes: {#{.map{|t,v| "#{t}: #{v}"}.join ', '}}" end end end |
.intermediate_channel_extname(*media) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ffmprb/process.rb', line 20 def intermediate_channel_extname(*media) if media == [:video] '.y4m' elsif media == [:audio] '.wav' elsif media.sort == [:audio, :video] '.flv' else fail Error, "I don't know how to channel [#{media.join ', '}]" end end |
.output_audio_options ⇒ Object
38 39 40 41 42 |
# File 'lib/ffmprb/process.rb', line 38 def { encoder: output_audio_encoder } end |
.output_video_options ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ffmprb/process.rb', line 32 def { resolution: output_video_resolution, fps: output_video_fps } end |
Instance Method Details
#input(io, **opts) ⇒ Object
101 102 103 104 105 |
# File 'lib/ffmprb/process.rb', line 101 def input(io, **opts) Input.new(io, self, **self.class..merge(opts)).tap do |inp| @inputs << inp end end |
#input_label(input) ⇒ Object
113 114 115 |
# File 'lib/ffmprb/process.rb', line 113 def input_label(input) @inputs.index input end |
#output(io, video: true, audio: true, &blk) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/ffmprb/process.rb', line 117 def output(io, video: true, audio: true, &blk) Output.new(io, self, video: channel_params(video, self.class.), audio: channel_params(audio, self.class.) ).tap do |out| @outputs << out out.instance_exec &blk if blk end end |
#output_index(output) ⇒ Object
127 128 129 |
# File 'lib/ffmprb/process.rb', line 127 def output_index(output) @outputs.index output end |
#run(limit: nil) ⇒ Object
NOTE the one and the only entry-point processing function which spawns threads etc
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ffmprb/process.rb', line 132 def run(limit: nil) # TODO (async: false) # NOTE this is both for the future async: option and according to # the threading policy (a parent death will be noticed and handled by children) thr = Util::Thread.new do # NOTE yes, an exception can occur anytime, and we'll just die, it's ok, see above # XXX just to return something -- no apparent practical use cmd = command Util.ffmpeg(*cmd, limit: limit, timeout: timeout, ignore_broken_pipe: @ignore_broken_pipe).tap do |res| Util::Thread.join_children! limit, timeout: timeout end end thr.value if thr.join limit # NOTE should not block for more than limit end |
#temp_input(extname) ⇒ Object
XXX SPEC ME
107 108 109 110 111 |
# File 'lib/ffmprb/process.rb', line 107 def temp_input(extname) # XXX SPEC ME input(nil).tap do |inp| inp.temporise! extname end end |