Class: Lolcommits::CaptureMacAnimated

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

Instance Attribute Summary

Attributes inherited from Capturer

#animated_duration, #capture_delay, #capture_device, #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
27
28
# File 'lib/lolcommits/capturer/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"
  return unless File.exist?(video_location)
  # get fps for ffmpeg output stream configuration
  fps = video_fps(video_location)
  # convert raw video to png frames with ffmpeg
  system_call "ffmpeg -v quiet -i \"#{video_location}\" -t #{animated_duration} -r #{fps} \"#{frames_location}/%09d.png\""

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

  # create the looping animated gif from frames (picks nth frame with seq,
  # quotes output and concats to a single line with tr)
  seq_command = "seq -f \"\\\"#{frames_location}/%09g.png\\\"\" 1 #{skip} #{Dir["#{frames_location}/*"].length} | tr '\\n' ' '"
  seq_frame_files = system_call(seq_command, true)
  # convert to animated gif with delay and gif optimisation
  system_call "convert -layers OptimizeTransparency -delay #{delay} -loop 0 #{seq_frame_files} -coalesce \"#{snapshot_location}\" > /dev/null"
end

#executable_pathObject



30
31
32
# File 'lib/lolcommits/capturer/capture_mac_animated.rb', line 30

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