public
Description: Ruby interface to the ffmpeg C library
Homepage: http://blog.gwikzone.org/
Clone URL: git://github.com/gwik/ffmpeg-ruby.git
ffmpeg-ruby / animated_gif_example.rb
100644 26 lines (21 sloc) 0.545 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'rubygems'
require 'ffmpeg'
require 'RMagick'
 
video = FFMPEG::InputFormat.new('spec/data/alligator.mp4')
stream = video.first_video_stream
stream.seek 12
 
i = 0
image_list = Magick::ImageList.new
 
# pts is presentation timestamp
# dts is decoding timestamp
stream.decode_frame do |frame, pts, dts|
  i += 1
  # stop when decoding timestamp (~position) reach 18
  break if dts > 18
  # decode 1 frame for 5
  next unless i % 5 == 0
  image_list.from_blob(frame.to_ppm)
end
 
puts i
image_list.delay = 20
image_list.write('animated.gif')