Class: Lolcommits::CaptureMacAnimated

Inherits:
Capturer
  • Object
show all
Defined in:
lib/lolcommits/capture_mac_animated.rb

Instance Attribute Summary

Attributes inherited from Capturer

#animated_duration, #capture_delay, #capture_device, #font, #frames_location, #snapshot_location, #video_location

Instance Method Summary collapse

Methods inherited from Capturer

#initialize

Constructor Details

This class inherits a constructor from Lolcommits::Capturer

Instance Method Details

#captureObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lolcommits/capture_mac_animated.rb', line 4

def capture
  # make a fresh frames directory
  FileUtils.rm_rf(frames_location)
  FileUtils.mkdir_p(frames_location)

  # capture the raw video with videosnap
  system_call "#{executable_path} -s 240 #{capture_device_string}#{capture_delay_string}-t #{animated_duration} --no-audio #{video_location} > /dev/null"
  if File.exists?(video_location)
    # convert raw video to png frames with ffmpeg
    system_call "ffmpeg -v quiet -i #{video_location} -t #{animated_duration} #{frames_location}/%09d.png"

    # use fps to set delay and number of frames to skip (for lower filesized gifs)
    fps   = video_fps(video_location)
    skip  = frame_skip(fps)
    delay = frame_delay(fps, skip)
    debug "Capturer: anaimated gif choosing every #{skip} frames with a frame delay of #{delay}"

    # create the looping animated gif from frames (picks nth frame with seq)
    seq_command = "seq -f #{frames_location}/%09g.png 1 #{skip} #{Dir["#{frames_location}/*"].length}"
    # convert to animated gif with delay and gif optimisation
    system_call "convert -layers OptimizeTransparency -delay #{delay} -loop 0 `#{seq_command}` -coalesce #{snapshot_location}"
  end
end

#executable_pathObject



28
29
30
# File 'lib/lolcommits/capture_mac_animated.rb', line 28

def executable_path
  File.join(Configuration::LOLCOMMITS_ROOT, 'vendor', 'ext', 'videosnap', 'videosnap')
end