Module: Ffmprb

Includes:
Util::ProcVis
Defined in:
lib/ffmprb.rb,
lib/defaults.rb,
lib/ffmprb/file.rb,
lib/ffmprb/util.rb,
lib/ffmprb/filter.rb,
lib/ffmprb/process.rb,
lib/ffmprb/version.rb,
lib/ffmprb/execution.rb,
lib/ffmprb/file/sample.rb,
lib/ffmprb/util/thread.rb,
lib/ffmprb/find_silence.rb,
lib/ffmprb/process/input.rb,
lib/ffmprb/util/proc_vis.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/paced.rb,
lib/ffmprb/process/input/cropped.rb,
lib/ffmprb/process/input/looping.rb,
lib/ffmprb/file/threaded_buffered.rb,
lib/ffmprb/process/input/reversed.rb,
lib/ffmprb/process/input/channeled.rb,
lib/ffmprb/util/threaded_io_buffer.rb,
lib/ffmprb/process/input/chain_base.rb,
lib/ffmprb/process/input/postprocessed.rb

Defined Under Namespace

Modules: Filter, Util Classes: Error, Execution, File, Process

Constant Summary collapse

ENV_VAR_FALSE_REGEX =
/^(0|no?|false)?$/i
CGA =
'320x200'
QVGA =
'320x240'
HD_480p =
'854x480'
HD_720p =
'1280x720'
HD_1080p =
'1920x1080'
HD_4K =
'3840x2160'
VERSION =
'0.12.3'
GEM_GITHUB_URL =
'https://github.com/costa/ffmprb'
FIREBASE_AVAILABLE =
begin
  require 'firebase'
  true
rescue Exception
end

Constants included from Util::ProcVis

Util::ProcVis::UPDATE_PERIOD_SEC

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util::ProcVis

included

Class Attribute Details

.debugObject

Returns the value of attribute debug.



42
43
44
# File 'lib/ffmprb.rb', line 42

def debug
  @debug
end

.ffmpeg_debugObject

Returns the value of attribute ffmpeg_debug.



42
43
44
# File 'lib/ffmprb.rb', line 42

def ffmpeg_debug
  @ffmpeg_debug
end

.log_levelObject

Returns the value of attribute log_level.



42
43
44
# File 'lib/ffmprb.rb', line 42

def log_level
  @log_level
end

Class Method Details

.find_silence(input_file, output_file) ⇒ Object

NOTE not for streaming just yet



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ffmprb/find_silence.rb', line 6

def find_silence(input_file, output_file)
  path = "#{input_file.path}->#{output_file.path}"
  logger.debug{"Finding silence (#{path})"}
  silence = []
  Util.ffmpeg('-i', input_file.path, *find_silence_detect_args, output_file.path).
    scan(SILENCE_DETECT_REGEX).each do |mark, time|
    time = time.to_f

    case mark
    when 'start'
      silence << OpenStruct.new(start_at: time)
    when 'end'
      if silence.empty?
        silence << OpenStruct.new(start_at: 0.0, end_at: time)
      else
        fail Error, "ffmpeg is being stupid: silence_end with no silence_start"  if silence.last.end_at
        silence.last.end_at = time
      end
    else
      Ffmprb.warn "Unknown silence mark: #{mark}"
    end
  end
  logger.debug{
    silence_map = silence.map{|t,v| "#{t}: #{v}"}
    "Found silence (#{path}): [#{silence_map}]"
  }
  silence
end

.loggerObject



44
45
46
47
48
# File 'lib/ffmprb.rb', line 44

def logger
  @logger ||= Logger.new(STDERR).tap do |logger|
    logger.level = debug ? Logger::DEBUG : Ffmprb.log_level
  end
end

.logger=(logger) ⇒ Object



50
51
52
53
# File 'lib/ffmprb.rb', line 50

def logger=(logger)
  @logger.close  if @logger
  @logger = logger
end

.process(*args, name: nil, **opts, &blk) ⇒ Object Also known as: action!

TODO limit:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ffmprb.rb', line 24

def process(*args, name: nil, **opts, &blk)
  fail Error, "process: nothing ;( gimme a block!"  unless blk

  name ||=  blk.source_location.map(&:to_s).map{ |s| File.basename s.to_s, File.extname(s) }.join(':')
  process = Process.new(name: name, **opts)
  # TODO simply include the ProcVis if it makes into a gem
  proc_vis_node process  if respond_to? :proc_vis_node
  logger.debug{"Starting process with #{args} #{opts} in #{blk.source_location}"}

  process.instance_exec *args, &blk
  logger.debug{"Initialized process with #{args} #{opts} in #{blk.source_location}"}

  process.run.tap do
    logger.debug{"Finished process with #{args} #{opts} in #{blk.source_location}"}
  end
end