Class: Converted::GIF

Inherits:
Object
  • Object
show all
Defined in:
lib/converted/gif.rb

Constant Summary collapse

TMP_DIR =

Define the tmp directory path

File.join(Dir.pwd, 'tmp')

Instance Method Summary collapse

Constructor Details

#initialize(input_file) ⇒ GIF

Returns a new instance of GIF.



8
9
10
11
12
13
# File 'lib/converted/gif.rb', line 8

def initialize(input_file)
  @input_file = input_file
  unless File.exist?(@input_file)
    raise "Error: Input file #{@input_file} does not exist."
  end
end

Instance Method Details

#convert_to_avi(output_file = nil) ⇒ Object



51
52
53
54
# File 'lib/converted/gif.rb', line 51

def convert_to_avi(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'avi'))
  run_ffmpeg_command("-c:v mpeg4 -vtag xvid -qscale:v 3", output_file, "AVI")
end

#convert_to_avif(output_file = nil) ⇒ Object



30
31
32
33
# File 'lib/converted/gif.rb', line 30

def convert_to_avif(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'avif'))
  run_ffmpeg_command("-c:v libaom-av1 -crf 30", output_file, "AVIF")
end

#convert_to_bmp(output_file = nil, with_transparency: false) ⇒ Object



35
36
37
38
39
# File 'lib/converted/gif.rb', line 35

def convert_to_bmp(output_file = nil, with_transparency: false)
  output_file ||= tmp_file(change_extension(@input_file, 'bmp'))
  options = with_transparency ? "" : "-vf 'format=bgr24,pad=iw:ih:0:0:color=white'"
  run_ffmpeg_command(options, output_file, "BMP")
end

#convert_to_ico(output_file = nil) ⇒ Object



41
42
43
44
# File 'lib/converted/gif.rb', line 41

def convert_to_ico(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'ico'))
  run_ffmpeg_command("", output_file, "ICO")
end

#convert_to_jpg(output_file = nil) ⇒ Object



15
16
17
18
# File 'lib/converted/gif.rb', line 15

def convert_to_jpg(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'jpg'))
  run_ffmpeg_command("-vf 'format=yuvj422p,pad=iw:ih:0:0:color=white'", output_file, "JPG")
end

#convert_to_mp4(output_file = nil) ⇒ Object



56
57
58
59
# File 'lib/converted/gif.rb', line 56

def convert_to_mp4(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'mp4'))
  run_ffmpeg_command("-c:v libx264 -crf 23 -preset fast", output_file, "MP4")
end

#convert_to_png(output_file = nil) ⇒ Object



20
21
22
23
# File 'lib/converted/gif.rb', line 20

def convert_to_png(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'png'))
  run_ffmpeg_command("", output_file, "PNG")
end

#convert_to_webm(output_file = nil) ⇒ Object



46
47
48
49
# File 'lib/converted/gif.rb', line 46

def convert_to_webm(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'webm'))
  run_ffmpeg_command("-c:v libvpx-vp9 -b:v 1M -an", output_file, "WEBM")
end

#convert_to_webp(output_file = nil) ⇒ Object



25
26
27
28
# File 'lib/converted/gif.rb', line 25

def convert_to_webp(output_file = nil)
  output_file ||= tmp_file(change_extension(@input_file, 'webp'))
  run_ffmpeg_command("-c:v libwebp -lossless 1", output_file, "WEBP")
end