Front Page&Projects24 Mar 2009 05:25 pm
Here’s how to grab a single frame from a live video stream using GStreamer on Linux in Ruby.
The trick is to use the “last_buffer” property on your video sink. That contains the last frame that was displayed to your screen.
You can use RMagick to convert that into something you can use like this:
#!/usr/bin/ruby
require 'gst'
require 'RMagick'
@pipe = Gst::Pipeline.new
@source = Gst::ElementFactory.make("v4l2src")
@sink = Gst::ElementFactory.make("xvimagesink")
@pipe.add(@source,@sink)
@source >> @sink
@pipe.play
[ ... Later ... ]
# This is the actual capture.
capture = Image.from_blob(@sink.last_buffer.data).first