Sha256: 66ceaf77886e6bb27f4be5b02c857660f1d762b6fe2d2f1e33961dc8d4178562

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

module Ffmprb

  class << self

    def find_silence(input_file, output_file)
      logger.debug "Finding silence (#{input_file.path}->#{output_file.path})"
      silence = []
      Util.ffmpeg('-i', input_file.path, *find_silence_detect_options, 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 (#{input_file.path}->#{output_file.path}): [#{silence.map{|t,v| "#{t}: #{v}"}}]"
      silence
    end

    private

    SILENCE_DETECT_REGEX = /\[silencedetect\s.*\]\s*silence_(\w+):\s*(\d+\.?d*)/

    def find_silence_detect_options
      Filter.complex_options Filter.silencedetect
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffmprb-0.9.4 lib/ffmprb/find_silence.rb
ffmprb-0.9.3 lib/ffmprb/find_silence.rb
ffmprb-0.9.2 lib/ffmprb/find_silence.rb
ffmprb-0.9.1 lib/ffmprb/find_silence.rb
ffmprb-0.9.0 lib/ffmprb/find_silence.rb
ffmprb-0.7.5 lib/ffmprb/find_silence.rb