Class: MultimediaParadise::Video::Watermark

Inherits:
Base
  • Object
show all
Defined in:
lib/multimedia_paradise/video/watermark.rb

Overview

MultimediaParadise::Watermark

Constant Summary collapse

USE_THIS_IMAGE_AS_WATERMARK =
#

USE_THIS_IMAGE_AS_WATERMARK

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

#

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

'/home/x/data/images/STD/YIN_YANG.png'
OVERLAY_POSITION =
#

OVERLAY_POSITION

This may specify where the overlayed image is situated.

#
'8:12'

Constants inherited from Base

Base::ERROR, Base::ERROR_LINE, Base::NAMESPACE, Base::USE_THIS_NAMESPACE_FOR_THE_COLOURS, Base::USE_THIS_NAMESPACE_FOR_THE_CORE_COLOURS

Instance Method Summary collapse

Methods inherited from Base

[], #actions, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #cartoons_directory?, #clear_the_internal_hash, #cliner, #cliner_with_time_stamp, #colourized_comment, #copy_file, #crimson, #dataset_from_file_video_collection, #dd_mm_yyyy, #debug?, #default_readlines, #directory_to_realvids?, #do_not_use_opn, #dodgerblue, #does_the_video_player_support_this_commandline?, #e, #ecomment, #ecrimson, #efancy, #enable_debug, #ensure_main_encoding, #ensure_that_the_output_directory_exists, #eparse, #erev, #esystem, #ewarn, #file_video_collection?, #filter_for_audio_files, #filter_for_video_files, #forestgreen, #gold, #grey, #hh_mm_ss, #home_x_video?, #indianred, #infer_the_namespace, #internal_hash?, #is_audio_file?, #is_mkv?, #is_mp3?, #is_mp4?, #is_multimedia_file?, #is_on_roebe?, #is_video_file?, #konsole_colour_peru, #lightblue, #lightgreen, #load_yaml, #local_audio_directory?, #log_dir?, #map_symbol_to_locally_existing_file, #mediumorchid, #mediumpurple, #mediumslateblue, #mkdir, #move_file, #namespace?, #no_file_exists, #no_file_exists_at, #olive, #olivedrab, #opne, #opnecomment, #opnn, #orange, #palegoldenrod, #palegreen, #powderblue, #project_base_directory?, #rds, #register_sigint, #remove_file, #report_pwd, #reset_the_internal_hash, #return_all_video_files, #return_pwd, #return_random_video, #rev, #royalblue, #save_what_into, #sdir, #seagreen, #seconds_to_time_format, #select_only_video_files_from, #set_be_verbose, #set_use_colours, #sfancy, #sfile, #simp, #skyblue, #slateblue, #springgreen, #steelblue, #swarn, #teal, #time_right_now, #to_hh_mm_ss, #tomato, #true_rev, #try_to_rename_kde_konsole_tab, #ucliner, #use_colours?, #use_opn?, #use_which_video_player?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel

Methods included from CommandlineArgumentsModule

#all_input_starts_with_a_number?, #commandline_arguments?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Watermark

#

initialize

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

The second input is the image we use as watermark.

#


61
62
63
64
65
66
67
68
69
70
# File 'lib/multimedia_paradise/video/watermark.rb', line 61

def initialize(
    commandline_arguments       = ARGV,
    run_already                 = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Instance Method Details

#determine_which_image_to_use_and_which_videofile_to_useObject

#

determine_which_image_to_use_and_which_videofile_to_use

#


233
234
235
236
237
238
# File 'lib/multimedia_paradise/video/watermark.rb', line 233

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

#output_file?Boolean Also known as: output?

#

output_file? (output tag)

#

Returns:

  • (Boolean)


154
155
156
# File 'lib/multimedia_paradise/video/watermark.rb', line 154

def output_file?
  @name_of_output_file
end

#process_each_video_nowObject

#

process_each_video_now

#


208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/multimedia_paradise/video/watermark.rb', line 208

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

#reportObject

#

report

#


147
148
149
# File 'lib/multimedia_paradise/video/watermark.rb', line 147

def report
  opnn; e "We stored at the location `#{sfile(output?)}`."
end

#resetObject

#

reset (reset tag)

#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/multimedia_paradise/video/watermark.rb', line 75

def reset
  super()
  infer_the_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

#runObject

#

run (run tag)

#


243
244
245
246
247
# File 'lib/multimedia_paradise/video/watermark.rb', line 243

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_fileObject

#

sanitize_name_of_output_file

#


140
141
142
# File 'lib/multimedia_paradise/video/watermark.rb', line 140

def sanitize_name_of_output_file
  @name_of_output_file << File.extname(@videofile.first)
end

#set_commandline_arguments(i) ⇒ Object

#

set_commandline_arguments

#


224
225
226
227
228
# File 'lib/multimedia_paradise/video/watermark.rb', line 224

def set_commandline_arguments(
    i
  )
  @commandline_arguments = [i].flatten.compact
end

#set_image_to_use_as_watermark(i = :rand) ⇒ Object Also known as: set_image

#

set_image_to_use_as_watermark

Set the image you want to use for watermarking here.

#


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/multimedia_paradise/video/watermark.rb', line 182

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

#set_name_of_output_file(i = 'watermarked_video_file_'+ File.basename( input?.gsub(/#{File.extname(input_file?)}/,'') )) ⇒ Object

#

set_name_of_output_file

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

#


163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/multimedia_paradise/video/watermark.rb', line 163

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 = '') ⇒ Object

#

set_videofile

#


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/multimedia_paradise/video/watermark.rb', line 106

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_helpObject

#

show_help

#


129
130
131
132
133
134
135
# File 'lib/multimedia_paradise/video/watermark.rb', line 129

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

#videofile?Boolean Also known as: input_file?, video_file?, v?, input?

#

videofile?

#

Returns:

  • (Boolean)


94
95
96
97
98
# File 'lib/multimedia_paradise/video/watermark.rb', line 94

def videofile?
  _ = @videofile
  _ = _.first if _.is_a? Array
  _.to_s # Must return a String.
end