5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/lolcommits/animated_gif.rb', line 5
def create(video_path:, output_path:)
unless File.exist?(video_path)
debug "**warning** unable to create animated gif, no video at #{video_path}"
return
end
debug "creating animated gif at #{output_path}"
system_call "ffmpeg -nostats -v quiet -i \"#{video_path}\" \"#{frames_dir}/%09d.png\" > #{null_string}"
fps = video_fps(video_path)
skip = frame_skip(fps)
delay = frame_delay(fps, skip)
debug "animated gif choosing every #{skip} frames with a frame delay of #{delay} (video fps: #{fps})"
Dir["#{frames_dir}/*.png"].each do |frame_filename|
basename = File.basename(frame_filename)
frame_number = basename.split('.').first.to_i
File.delete(frame_filename) if frame_number % skip != 0
end
system_call "convert -layers OptimizeTransparency -delay #{delay} -loop 0 \"#{frames_dir}/*.png\" -coalesce \"#{output_path}\""
FileUtils.rm_rf(frames_dir)
end
|