Skip to content

Instantly share code, notes, and snippets.

@poqudrof poqudrof/stream.rb
Created Jul 28, 2016

What would you like to do?
Stream Gstreamer launch
## You can take pictures via Entangle, or in command line.
require 'fileutils'
# First argument is starting number
name = "capture"
output_name = "playing/capture000000.jpg"
# start with zero, to take from input arguments
id = ARGV[0].to_i
## Start Gstreamer
pid = Process.fork do
`gst-launch-0.10 multifilesrc location=playing/capture%06d.jpg start-index=0 stop-index=0 loop=true caps="image/jpeg,framerate=\(fraction\)1/1" ! jpegdec ! ffmpegcolorspace ! videorate ! v4l2sink device=/dev/video0`
file_name = name + id.to_s.rjust(6, "0") + ".jpg"
p file_name
p FileTest.exists? file_name
## update with the latest picture
while true do
if FileTest.exists? file_name
p "Putting image: " + id.to_s
FileUtils.cp file_name, output_name
id = id +1
file_name = name + id.to_s.rjust(6, "0") + ".jpg"
sleep 1
## Stream the video to V4L2:
# gphoto2 --stdout --capture-movie | gst-launch-0.10 fdsrc ! decodebin2 name=dec ! queue ! ffmpegcolorspace ! v4l2sink device=/dev/video0
## Stream x photos to V4L2
# gst-launch-0.10 multifilesrc location=capture%06d.jpg start-index=5 stop-index=18 loop=true caps=image/jpeg,framerate=\(fraction\)1/1 ! jpegdec ! ffmpegcolorspace ! videorate ! v4l2sink device=/dev/video0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.