class MultimediaParadise::Video::VideoInformation

Constants

AUDIO_STREAMS
#

AUDIO_STREAMS

#
NAMESPACE
#

NAMESPACE

#
SHALL_WE_DEBUG
#

SHALL_WE_DEBUG

#
VIDEO_STREAMS
#

VIDEO_STREAMS

The registered videostreams come here.

#

Public Class Methods

new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/video/video_information.rb, line 62
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_files(i)
  run if run_already
end

Public Instance Methods

audio()
Alias for: audio?
audio?() click to toggle source
#

audio?

#
# File lib/multimedia_paradise/video/video_information.rb, line 145
def audio?
  @audio
end
Also aliased as: audio
be_verbose?() click to toggle source
#

be_verbose?

#
# File lib/multimedia_paradise/video/video_information.rb, line 152
def be_verbose?
  @be_verbose
end
bitrate?() click to toggle source
#

bitrate?

#
# File lib/multimedia_paradise/video/video_information.rb, line 255
def bitrate?
  @bitrate
end
data()
Alias for: data?
data?() click to toggle source
#

data?

#
# File lib/multimedia_paradise/video/video_information.rb, line 218
def data?
  @data
end
Also aliased as: data
decompose(i) click to toggle source
#

decompose

The input will hold all information.

#
# File lib/multimedia_paradise/video/video_information.rb, line 376
def decompose(i)
  i = i.split(N)
  if SHALL_WE_DEBUG
    opnn; e 'The user wants to debug, so we will output the information'
    opnn; e 'that is to be decomposed:'
    pp i
  end
  grab_all_streams = i.select {|entry|
    entry.strip.include? 'Stream #' # Grab all video and audio streams.
  }
  set_audio(grab_all_streams)
  set_video(grab_all_streams)
  set_resolution(grab_all_streams)
end
determine_duration_of_the_file() click to toggle source
#

determine_duration_of_the_file

#
# File lib/multimedia_paradise/video/video_information.rb, line 308
def determine_duration_of_the_file
  use_this_regex = /Duration: (\d{1,2}:\d{1,2}:\d{1,2}.\d{1,2})/ # See: http://rubular.com/r/NYoZ9GMryH
  input_stream? =~ use_this_regex
  set_duration($1.to_s.dup)
end
duration?() click to toggle source
#

duration?

#
# File lib/multimedia_paradise/video/video_information.rb, line 317
def duration?
  @duration
end
file?()
Alias for: files?
files?() click to toggle source
#

files?

#
# File lib/multimedia_paradise/video/video_information.rb, line 114
def files?
  @files
end
Also aliased as: input?, file?
input?()
Alias for: files?
input_stream?() click to toggle source
#

input_stream?

#
# File lib/multimedia_paradise/video/video_information.rb, line 299
def input_stream?
  inspect_this_file_via_ffmpeg(
    files?.first
  )
end
inspect_this_file_via_ffmpeg( the_file = files?.first ) click to toggle source
#

inspect_this_file_via_ffmpeg

The argument given to this method should be an existing file.

#
# File lib/multimedia_paradise/video/video_information.rb, line 191
def inspect_this_file_via_ffmpeg(
    the_file = files?.first
  )
  `ffmpeg -i #{the_file} 2>&1` # The input-stream.
end
name?() click to toggle source
#

name?

#
# File lib/multimedia_paradise/video/video_information.rb, line 122
def name?
  _ = file?
  _ = _.first if _.is_a? Array
  _
end
opnn() click to toggle source
#

opnn

#
Calls superclass method MultimediaParadise::Base#opnn
# File lib/multimedia_paradise/video/video_information.rb, line 269
def opnn
  super(NAMESPACE) if @report_the_namespace
end
populate_main_data() click to toggle source
#

populate_main_data

#
# File lib/multimedia_paradise/video/video_information.rb, line 175
def populate_main_data
  @data = [video?, audio?] # Build up @data.
end
report(report_the_namespace = true)
Alias for: verbose_report
report_audio_bitrate() click to toggle source
#

report_audio_bitrate

#
# File lib/multimedia_paradise/video/video_information.rb, line 241
def report_audio_bitrate
  regex = /bitrate: (\d+ kb\/s)/
  _ = inspect_this_file_via_ffmpeg
  _ =~ regex
  if $1
    set_bitrate($1)
    opnn; e 'The audio bitrate is:'
    opnn; e "  #{simp(bitrate?)}"
  end
end
report_audio_stream() click to toggle source
#

report_audio_stream

We try to report which audio stream we have, e. g. “.mp3”.

#
# File lib/multimedia_paradise/video/video_information.rb, line 227
def report_audio_stream
  if audio?
    opnn; e 'The audio stream is `'+sfancy(audio?)+'`.'
    if audio?.end_with? 'mp3' # Ok we have a .mp3 file. Report the audio-bitrate next.
      report_audio_bitrate
    end
  else
    opnn; e 'No audio stream could be found.'
  end
end
report_the_duration() click to toggle source
#

report_the_duration

This method will report the duration of that particular multimedia file.

#
# File lib/multimedia_paradise/video/video_information.rb, line 362
def report_the_duration
  duration = duration?
  opnn; e 'The duration of this file is `'+
          sfancy(duration.to_s)+'` seconds. '\
          '('+seagreen(
            to_hh_mm_ss(duration)
          )+')'
end
report_the_name_of_the_file() click to toggle source
#

report_the_name_of_the_file

#
# File lib/multimedia_paradise/video/video_information.rb, line 276
def report_the_name_of_the_file
  _ = name?
  if File.exist? _
    opnn; e "#{rev}The name of the video file is `#{simp(_)}`."
  end
end
report_the_resolution() click to toggle source
#

report_the_resolution

#
# File lib/multimedia_paradise/video/video_information.rb, line 351
def report_the_resolution
  print ' The video-resolution is '+
        sfancy(@resolution)+'.'
end
report_video_stream() click to toggle source
#

report_video_stream

#
# File lib/multimedia_paradise/video/video_information.rb, line 286
def report_video_stream
  if File.exist? name?
    opnn; print "The video stream is `#{sfancy(video?)}`."
    if @resolution
      report_the_resolution
    end
    e
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/video_information.rb, line 74
def reset
  super()
  set_audio # Set it to empty first.
  # ======================================================================= #
  # === @video
  # ======================================================================= #
  @video = nil
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
  # ======================================================================= #
  # === @data
  #
  # This Array will hold video and audio.
  # ======================================================================= #
  @data = []
  # ======================================================================= #
  # === @report_the_namespace
  # ======================================================================= #
  @report_the_namespace = true
  # ======================================================================= #
  # === resolution
  #
  # This will carry the video result, such as: 1280x720
  # ======================================================================= #
  @resolution = nil
  set_duration nil # Initialize it to nil specifically.
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/video_information.rb, line 413
def run
  files?.each {|the_file|
    if File.exist? the_file
      _ = inspect_this_file_via_ffmpeg(the_file)
      decompose(_)
      populate_main_data
      determine_duration_of_the_file
    else
      if be_verbose?
        opnn; e 'File at `'+sfile(the_file)+'` does not exist.'
      end
    end
  }
end
set_audio(i = nil) click to toggle source
#

set_audio (audio tag)

#
# File lib/multimedia_paradise/video/video_information.rb, line 159
def set_audio(i = nil)
  if i.is_a? Array
    i = i.select {|entry| entry.include? 'Audio:' }
    set_hertz(i) if i.include? ' Hz'
    i = i.first unless i.empty?
  end
  if i
    i = AUDIO_STREAMS.find { |s| i.include?(s.to_s) }
    i = nil if i.is_a? Array # Then it must be empty.
  end
  @audio = i
end
set_bitrate(i) click to toggle source
#

set_bitrate

#
# File lib/multimedia_paradise/video/video_information.rb, line 262
def set_bitrate(i)
  @bitrate = i.to_s
end
set_duration(i = nil) click to toggle source
#

set_duration

#
# File lib/multimedia_paradise/video/video_information.rb, line 341
def set_duration(i = nil)
  if i and i.is_a?(String) and i.include?(':')
    i = MultimediaParadise.long_format_to_milliseconds(i).to_f / 1000.0
  end
  @duration = i
end
set_files(i = '') click to toggle source
#

set_files

#
# File lib/multimedia_paradise/video/video_information.rb, line 107
def set_files(i = '')
  @files = i
end
set_hertz(i) click to toggle source
#

set_hertz

#
# File lib/multimedia_paradise/video/video_information.rb, line 138
def set_hertz(i)
  @hertz = i.scan(/(\d+) Hz/).flatten.first if i.include? ' Hz'
end
set_resolution(i) click to toggle source
#

set_resolution

#
# File lib/multimedia_paradise/video/video_information.rb, line 394
def set_resolution(i)
  if i
    if i.is_a? Array
      selection = i.select {|entry|
        entry.include?('Video: ')
      }.first
      if selection.include? 'x'
        i = selection.scan(
              /\d{2,4}x\d{2,4}/
            ).flatten.first.to_s.strip
      end
    end
    @resolution = i
  end
end
set_video(i) click to toggle source
#

set_video (video tag)

#
# File lib/multimedia_paradise/video/video_information.rb, line 200
def set_video(i)
  if i.is_a? Array
    i = i.select {|entry| entry.include? 'Video:' }
    i = i.first unless i.empty?
  end
  result = VIDEO_STREAMS.find { |s| i.include?(s) }
  # ======================================================================= #
  # Handle XVID next:
  # ======================================================================= #
  if result == 'mpeg4' and i.include?('XVID')
    result << ' (XVID)'
  end
  @video = result
end
verbose_report(report_the_namespace = true) click to toggle source
#

verbose_report

This method will report the name, the video stream and the audio stream.

#
# File lib/multimedia_paradise/video/video_information.rb, line 327
def verbose_report(report_the_namespace = true)
  case report_the_namespace
  when :do_not_report_the_namespace
    @report_the_namespace = false
  end
  report_the_name_of_the_file
  report_video_stream
  report_audio_stream
  report_the_duration if @duration
end
Also aliased as: report
video?() click to toggle source
#

video?

#
# File lib/multimedia_paradise/video/video_information.rb, line 131
def video?
  @video
end