class MultimediaParadise::Video::Watermark

Constants

NAMESPACE
#

NAMESPACE

#
OVERLAY_POSITION
#

OVERLAY_POSITION

This may specify where the overlayed image is situated.

#
USE_THIS_IMAGE_AS_WATERMARK
#

USE_THIS_IMAGE_AS_WATERMARK

Which image to use a watermark. This will become the ivar @image_to_use_as_watermark.

#

USE_THIS_IMAGE_AS_WATERMARK = ‘/home/x/DATA/IMG/NJOY/RandomBeachGal.jpg’

Public Class Methods

new( commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

The first input is the file that will be modified via a watermark.

The second input is the image we use as watermark.

#
# File lib/multimedia_paradise/video/watermark.rb, line 66
def initialize(
    commandline_arguments       = ARGV,
    run_already                 = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

determine_which_image_to_use_and_which_videofile_to_use() click to toggle source
#

determine_which_image_to_use_and_which_videofile_to_use

#
# File lib/multimedia_paradise/video/watermark.rb, line 241
def determine_which_image_to_use_and_which_videofile_to_use
  first_argument  = @commandline_arguments.first
  second_argument = @commandline_arguments[1]
  set_videofile(first_argument)
  set_image(second_argument)
end
input?()
Alias for: videofile?
input_file?()
Alias for: videofile?
output?()
Alias for: output_file?
output_file?() click to toggle source
#

output_file? (output tag)

#
# File lib/multimedia_paradise/video/watermark.rb, line 162
def output_file?
  @name_of_output_file
end
Also aliased as: output?
process_each_video_now() click to toggle source
#

process_each_video_now

#
# File lib/multimedia_paradise/video/watermark.rb, line 216
def process_each_video_now
  @videofile.each {|entry|
    _  = "ffmpeg -i #{entry}".dup
    _ << ' -strict -2'
    _ << ' -y' # We will always overwrite, hence this option.
    _ << ' -vf "movie='+@image_to_use_as_watermark+
         ' [watermark]; [in][watermark] overlay='+OVERLAY_POSITION+' [out]" '
    _ << output_file?
    e simp(_) # Better to have colours.
    system(_)
  }
end
report() click to toggle source
#

report

#
# File lib/multimedia_paradise/video/watermark.rb, line 155
def report
  opnn; e "We stored at the location `#{sfile(output?)}`."
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/watermark.rb, line 80
def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @videofile
  # ======================================================================= #
  @videofile = nil
  # ======================================================================= #
  # Provide a default watermark-logo next.
  # ======================================================================= #
  set_image_to_use_as_watermark(
    USE_THIS_IMAGE_AS_WATERMARK
  )
  set_name_of_output_file
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/watermark.rb, line 251
def run
  determine_which_image_to_use_and_which_videofile_to_use
  sanitize_name_of_output_file
  process_each_video_now
end
sanitize_name_of_output_file() click to toggle source
#

sanitize_name_of_output_file

#
# File lib/multimedia_paradise/video/watermark.rb, line 148
def sanitize_name_of_output_file
  @name_of_output_file << File.extname(@videofile.first)
end
set_commandline_arguments( i ) click to toggle source
#

set_commandline_arguments

#
# File lib/multimedia_paradise/video/watermark.rb, line 232
def set_commandline_arguments(
    i
  )
  @commandline_arguments = [i].flatten.compact
end
set_image(i = :rand)
set_image_to_use_as_watermark(i = :rand) click to toggle source
#

set_image_to_use_as_watermark

Set the image you want to use for watermarking here.

#
# File lib/multimedia_paradise/video/watermark.rb, line 190
def set_image_to_use_as_watermark(i = :rand)
  i = i.to_s
  if i.include? '--'
    i = i.scan(/-?-?image=(.+)/).flatten.first.to_s
  end
  case i
  # ======================================================================= #
  # === rand
  # ======================================================================= #
  when /^rand/
    i = Dir[File.dirname(USE_THIS_IMAGE_AS_WATERMARK)+'/*'].sample
  else
    if Cyberweb.web_images_does_include?(i)
      i = Cyberweb.get_webimage(i)
    end
  end
  # ======================================================================= #
  # Next, assign to @image_to_use_as_watermark. We will use
  # this as path to the image file in question.
  # ======================================================================= #
  @image_to_use_as_watermark = i
end
Also aliased as: set_image
set_name_of_output_file( i = 'watermarked_video_file_'+ File.basename( input?.gsub(/ click to toggle source
#

set_name_of_output_file

This method-call must be after the input has been determined.

#
# File lib/multimedia_paradise/video/watermark.rb, line 171
def set_name_of_output_file(
    i = 'watermarked_video_file_'+
        File.basename(
          input?.gsub(/#{File.extname(input_file?)}/,'')
        )
  )
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  unless i.include? '/' # In this case, add the full path.
    i.prepend (Dir.pwd+'/').squeeze '/'
  end
  @name_of_output_file = i
end
set_videofile(i = '') click to toggle source
#

set_videofile

#
# File lib/multimedia_paradise/video/watermark.rb, line 114
def set_videofile(i = '')
  i = i.join(' ').strip if i.is_a? Array
  i = i.to_s.dup
  case i
  # ======================================================================= #
  # === watermark --help
  # ======================================================================= #
  when /^-?-?help$/
    show_help; exit
  # ======================================================================= #
  # === image=:austria
  # ======================================================================= #
  when /--image=(\S+)/ # This will match to "--image=:austria 273_Rambo.avi", see http://rubular.com/r/SwkpuftyFT
    set_image($1.to_s.dup)
    i.gsub!(/(--image=\S+)/, '') # Get rid of this part here.
  end
  @videofile = [i]
  set_name_of_output_file
end
show_help() click to toggle source
#

show_help

#
# File lib/multimedia_paradise/video/watermark.rb, line 137
def show_help
  opnn; e 'Currently these options are supported:'
  e
  e "  #{simp('--image=')} # use this image, as in \"--image=austria\" "\
    "to use the austrian flag"
  e
end
v?()
Alias for: videofile?
video_file?()
Alias for: videofile?
videofile?() click to toggle source
#

videofile?

#
# File lib/multimedia_paradise/video/watermark.rb, line 102
def videofile?
  _ = @videofile
  _ = _.first if _.is_a? Array
  _.to_s # Must return a String.
end
Also aliased as: input_file?, video_file?, v?, input?