class MultimediaParadise::AnalyseMultimediaFile

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

[](i = '') click to toggle source
#

MultimediaParadise::AnalyseMultimediaFile[]

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 172
def self.[](i = '')
  new(i)
end
new( commandline_arguments = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 31
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

analyze_this_result(i) click to toggle source
#

analyze_this_result

This method will analyse the result that “ffmpeg -i” gave us.

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 97
def analyze_this_result(i)
  # debug_this(i) # This can be enabled/disabled.
  if i.include? 'encoder         :'
    i =~ /encoder         : (.+)$/
    @encoder = $1.to_s.dup
    e 'The encoder is: '.ljust(@left_pad_n_times)+lightgreen(@encoder)
  end
  # ======================================================================= #
  # === Duration
  # ======================================================================= #
  if i.include? 'Duration: '
    i =~ /Duration: ([0-9:.]{2,12}),/ # See: https://rubular.com/r/Rq5lAuQnJUfiZd
    @duration = $1.to_s.dup
    n_seconds = return_this_duration_in_seconds(@duration)
    e 'The duration is: '.ljust(@left_pad_n_times)+
       lightgreen(@duration)+' ('+
         olive(n_seconds.to_s+' seconds')+
       ')'
  end
  # ======================================================================= #
  # === Stream #0:0:
  # ======================================================================= #
  if i.include? 'Stream #0:0:'
    if i.include? 'x'
      results = i.scan(/ (\d{1,3})x(\d{1,3}) /)
      e 'Video resolution is: '.ljust(@left_pad_n_times)+
         lightgreen(
           results.flatten.join('x').to_s
         )
    end
    # if i.include? 'Video:'
    #   e 'Codec: '.ljust(@left_pad_n_times)+
    #     'mpeg4'
    # end
  end
  if i.include? 'ENCODER   '
    # ===================================================================== #
    # ENCODER         : Lavf58.29.100
    # ===================================================================== #
    scanned_result = i.scan(/ENCODER\s*: (.+)/).flatten.first
    e 'The encoder is: '.ljust(@left_pad_n_times)+
       lightgreen(scanned_result)
  end
  if i.include? ': Audio: mp3, '
    e 'The file includes an audio stream '\
      '('+royalblue('mp3 format')+').'
  end
end
debug_this(i) click to toggle source
#

debug_this

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 87
def debug_this(i)
  e crimson('Debugging:')
  pp i
end
opnn(&block) click to toggle source
#

opnn

#
Calls superclass method MultimediaParadise::Base#opnn
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 56
def opnn(&block)
  super(NAMESPACE, &block)
end
process_the_input() click to toggle source
#

process_the_input

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 63
def process_the_input
  @commandline_arguments.each {|this_file|
    if is_a_multimedia_file?(this_file)
      opnn { :no_colon }
      e
      e
      e 'The multimedia file '+sfile(this_file)+' will be analysed next,'
      e "via #{orange('ffmpeg')}."
      e
      cmd = "ffmpeg -i #{this_file} 2>&1"
      e slateblue("  #{cmd}")
      e
      result = `#{cmd}`
      analyze_this_result(result)
    else
      opnn; e sfile(this_file)+' can not be analysed as it is not a (registered)'
      opnn; e 'audio/video (multimedia) file.'
    end
  }
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 45
def reset
  super()
  # ======================================================================= #
  # === @left_pad_n_times
  # ======================================================================= #
  @left_pad_n_times = 25
end
return_this_duration_in_seconds( i = '00:03:52.15' ) click to toggle source
#

return_this_duration_in_seconds

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 149
def return_this_duration_in_seconds(
    i = '00:03:52.15'
  )
  result = 0.0
  if i.include? ':'
    splitted = i.split(':')
    result += (splitted[0].to_f * 60 * 60)
    result += (splitted[1].to_f * 60) # These is the entry for minutes.
    result += splitted[2].to_f
  end
  result
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/multimedia/analyse_multimedia_file.rb, line 165
def run
  process_the_input
end