Class: Venus::BlurVideo

Inherits:
Object
  • Object
show all
Defined in:
lib/components/blur_video.rb

Class Method Summary collapse

Class Method Details

.blur_video(input_file, output_file, path: nil, blur_intensity: 20) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/components/blur_video.rb', line 5

def self.blur_video(input_file, output_file, path: nil, blur_intensity: 20)
  unless File.exist?(input_file)
    puts "File not found: #{input_file}"
    exit 1
  end

  unless blur_intensity.is_a?(Numeric) && blur_intensity >= 0
    puts 'Invalid blur intensity. It should be a non-negative number.'
    exit 1
  end

  output_file = "#{output_file}.mp4" unless output_file.end_with?('.mp4')
  output_path = path ? File.join(path, output_file) : File.join(Dir.pwd, output_file)

  command = "ffmpeg -i #{input_file} -vf 'boxblur=#{blur_intensity}:1' -c:a copy #{output_path}"
  execute_command(command)
end

.execute_command(command) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/components/blur_video.rb', line 23

def self.execute_command(command)
  Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
    while (line = stderr.gets)
      puts line
    end

    exit_status = wait_thr.value
    unless exit_status.success?
      puts "Error executing command: #{command}"
      exit 1
    end
  end
end

.process_arguments(args_string) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/components/blur_video.rb', line 37

def self.process_arguments(args_string)
  args = args_string.split

  if args.length < 2 || args.length > 4
    puts 'Usage: ruby main.rb <input_file> <output_file> [path] [blur_intensity]'
    exit 1
  end

  args
end