Class: VideoToAscii

Inherits:
Object
  • Object
show all
Defined in:
lib/video_to_ascii.rb,
lib/video_to_ascii/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVideoToAscii

Returns a new instance of VideoToAscii.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/video_to_ascii.rb', line 9

def initialize
  @ascii_images = []

  create_required_directories()
  capture_video()

  video = FFMPEG::Movie.new('videos/video.avi')

  screenshots_from_video(video)
  convert_all_images()

  puts "Press ENTER to watch."
  ready = gets.chomp!

  if ready
    system("clear")
    play_movie()
  end

  cleanup()
end

Instance Attribute Details

#ascii_imagesObject

Returns the value of attribute ascii_images.



7
8
9
# File 'lib/video_to_ascii.rb', line 7

def ascii_images
  @ascii_images
end

Instance Method Details

#capture_videoObject



35
36
37
38
39
40
41
42
# File 'lib/video_to_ascii.rb', line 35

def capture_video
  @video_length = ask("How long would you like the video to be?", Integer)
  path = File.expand_path('../bin/wacaw', File.dirname(__FILE__))

  puts "Recording Video for #{@video_length} seconds ..."

  `#{path} --video --duration #{@video_length} videos/video`
end

#cleanupObject



81
82
83
# File 'lib/video_to_ascii.rb', line 81

def cleanup
  `rm -rf images videos`
end

#convert_all_imagesObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/video_to_ascii.rb', line 57

def convert_all_images
  images = []
  Dir.glob('images/*.jpg') { |i| images << i }

  puts "asciiing the world"
  images.each do |image|
    convert_to_ascii(image)
    print "."
  end
end

#convert_to_ascii(image) ⇒ Object



76
77
78
79
# File 'lib/video_to_ascii.rb', line 76

def convert_to_ascii(image)
    image = AsciiArt.new("#{image}")
    @ascii_images << image.to_ascii_art(color: true, invert: true)
end

#create_required_directoriesObject



31
32
33
# File 'lib/video_to_ascii.rb', line 31

def create_required_directories
  `mkdir videos images`
end

#play_movieObject



68
69
70
71
72
73
74
# File 'lib/video_to_ascii.rb', line 68

def play_movie
  @ascii_images.each do |image|
    puts image
    sleep 0.1
    system("clear")
  end
end

#screenshots_from_video(video) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/video_to_ascii.rb', line 44

def screenshots_from_video(video)
  step_arr = []

  (0.0...video.duration).step(0.1).each { |x| step_arr << x.round(2) }

  #make sure steps are uniq or ffmpeg will crash and burn
  step_arr.uniq!

  step_arr.each_with_index do |step, i|
    video.screenshot("images/#{i}.jpg", seek_time: step)
  end
end