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/cropped.rb,
lib/ffmprb/process/input/looping.rb,
lib/ffmprb/file/threaded_buffered.rb,
lib/ffmprb/process/input/channeled.rb,
lib/ffmprb/util/threaded_io_buffer.rb,
lib/ffmprb/process/input/chain_base.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_720p =
'1280x720'
HD_1080p =
'1920x1080'
VERSION =
'0.11.3'
GEM_GITHUB_URL =
'https://github.com/showbox-oss/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.



39
40
41
# File 'lib/ffmprb.rb', line 39

def debug
  @debug
end

.ffmpeg_debugObject

Returns the value of attribute ffmpeg_debug.



39
40
41
# File 'lib/ffmprb.rb', line 39

def ffmpeg_debug
  @ffmpeg_debug
end

.log_levelObject

Returns the value of attribute log_level.



39
40
41
# File 'lib/ffmprb.rb', line 39

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
# 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 "Found silence (#{path}): [#{silence.map{|t,v| "#{t}: #{v}"}}]"
  silence
end

.loggerObject



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

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

.logger=(logger) ⇒ Object



47
48
49
50
# File 'lib/ffmprb.rb', line 47

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

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

TODO limit:



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

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)
  proc_vis_node process  if respond_to? :proc_vis_node  # XXX simply include the ProcVis if it makes into a gem
  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