Class: Lolcommits::CaptureLinuxAnimated

Inherits:
Capturer
  • Object
show all
Defined in:
lib/lolcommits/capturer/capture_linux_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
# File 'lib/lolcommits/capturer/capture_linux_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 ffmpeg video4linux2
  system_call "ffmpeg -v quiet -y -f video4linux2 -video_size 320x240 -i #{capture_device_string} -t #{capture_duration} \"#{video_location}\" > /dev/null"
  return unless File.exist?(video_location)
  # convert raw video to png frames with ffmpeg
  system_call "ffmpeg #{capture_delay_string} -v quiet -i \"#{video_location}\" -t #{animated_duration} \"#{frames_location}/%09d.png\" > /dev/null"

  # 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,
  # 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}\""
end