class MultimediaParadise::Video::SpeedUpVideo

Public Class Methods

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

MultimediaParadise::Video::SpeedUpVideo[]

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 127
def self.[](i = '')
  self.new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 23
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input_file(i)
  run if run_already
end

Public Instance Methods

input_file?() click to toggle source
#

input_file?

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 59
def input_file?
  @input_file
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/speed_up_video.rb, line 35
def reset
  super()
  # ======================================================================= #
  # 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_speed() click to toggle source
#

return_filter_for_doubling_the_speed

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 102
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_rate() click to toggle source
#

return_multiplier_for_speeding_up_the_audio_rate

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 66
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_rate() click to toggle source
#

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
#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 95
def return_multiplier_for_speeding_up_the_video_rate
  (return_multiplier_for_speeding_up_the_audio_rate.to_f / 4).to_s
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 109
def run
  # ======================================================================= #
  # We will speed up video and audio at the same time.
  # ======================================================================= #
  _ = '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'
  esystem _
end
set_input_file(i = '') click to toggle source
#

set_input_file

#
# File lib/multimedia_paradise/video/speed_up_video.rb, line 48
def set_input_file(i = '')
  if i.is_a? Array
    i = i.join(' ').strip
  end
  i = i.to_s.dup
  @input_file = i
end