Class: MultimediaParadise::Video::SpeedUpVideo

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

Overview

MultimediaParadise::Video::SpeedUpVideo

Constant Summary

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

Class Method Summary collapse

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?, #set_commandline_arguments

Constructor Details

#initialize(i = nil, run_already = true) ⇒ SpeedUpVideo

#

initialize

#


28
29
30
31
32
33
34
35
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 28

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input_file(i)
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

MultimediaParadise::Video::SpeedUpVideo[]

#


136
137
138
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 136

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#input_file?Boolean

#

input_file?

#

Returns:

  • (Boolean)


66
67
68
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 66

def input_file?
  @input_file
end

#resetObject

#

reset (reset tag)

#


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 40

def reset
  super()
  # ======================================================================= #
  # === @speed_up_by_n_percent
  #
  # Define the speed-up as percentage-number for the instance
  # variable @speed_up_by_n_percent. 200 effectively means
  # "double speed".
  # ======================================================================= #
  @speed_up_by_n_percent = 200 
end

#return_filter_for_doubling_the_speedObject

#

return_filter_for_doubling_the_speed

#


109
110
111
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 109

def return_filter_for_doubling_the_speed
  ' -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"'
end

#return_multiplier_for_speeding_up_the_audio_rateObject

#

return_multiplier_for_speeding_up_the_audio_rate

#


73
74
75
76
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 73

def return_multiplier_for_speeding_up_the_audio_rate
  result = (@speed_up_by_n_percent.to_f / 25).to_f
  return result.to_s
end

#return_multiplier_for_speeding_up_the_video_rateObject

#

return_multiplier_for_speeding_up_the_video_rate

This will return the number for the multiplier in use for videos. We can get it by using the multiplier 0.005 for percentage value.

Here is a table that shows these value:

 50% is 2.0  #  50 /   25
100% is 1.0  # 100 /  100
150% is 0.75 # 150 /  200
200% is 0.5  # 200 /  400
400% is 0.25 # 400 / 1600

Normalized towards 100 it is:

 50% is 2.0  # 200 /  100
100% is 1.0  # 100 /  100
150% is 0.75 #  75 /  100
200% is 0.5  #  50 /  100
400% is 0.25 #  25 /  100
#


102
103
104
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 102

def return_multiplier_for_speeding_up_the_video_rate
  (return_multiplier_for_speeding_up_the_audio_rate.to_f / 4).to_s
end

#runObject

#

run (run tag)

#


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 116

def run
  # ======================================================================= #
  # We will speed up video and audio at the same time, for the given
  # video at hand.
  # ======================================================================= #
  _ = 'ffmpeg'.dup
  _ << ' -i '+input_file?
  # _ << ' -filter_complex "[0:v]setpts='+return_multiplier_for_speeding_up_the_video_rate+
  #      'x*PTS[v];[0:a]atempo='+return_multiplier_for_speeding_up_the_audio_rate+'[a]"'
  _ << return_filter_for_doubling_the_speed
  _ << ' -map "[v]" -map "[a]"'
  _ << ' -y' # Overwrite it: yes. 
  _ << ' output.mkv'
  e
  esystem _, :steelblue, :use_a_newline
end

#set_input_file(i = '') ⇒ Object

#

set_input_file

#


55
56
57
58
59
60
61
# File 'lib/multimedia_paradise/video/speed_up_video.rb', line 55

def set_input_file(i = '')
  if i.is_a? Array
    i = i.join(' ').strip
  end
  i = i.to_s.dup
  @input_file = i
end