Skip to content

Instantly share code, notes, and snippets.

@sepastian
Created October 7, 2013 12:10
Show Gist options
  • Save sepastian/6866809 to your computer and use it in GitHub Desktop.
Save sepastian/6866809 to your computer and use it in GitHub Desktop.
Use gst-launch (gstreamer-tools) to capture single images and stream video from the command-line.
# Capture a single image and save it in JPEG format.
$ gst-launch v4l2src num-buffers=1 ! jpegenc ! filesink location=/tmp/test.jpg
# Stream video from a webcam.
$ gst-launch v4l2src ! xvimagesink
@alex-eri
Copy link

if camera supports MJPG
gst-launch-1.0 v4l2src num-buffers=1 ! image/jpeg,framerate=5/1,width=1280,height=960 ! jpegparse ! filesink location=/tmp/test2.jpg

@ramshivas
Copy link

Can I capture a single image and save it as BMP ?

@sepastian
Copy link
Author

@ramshivas not directly, I believe.

But you could use a tool such as ImageMagick to do the conversion, e.g.

convert /tmp/test2.jpg /tmp/test2.bmp

(However: why would you use BMP? If you need lossless, consider PNG or JP2K etc.)

@ramshivas
Copy link

ramshivas commented Sep 22, 2022

@ramshivas not directly, I believe.

But you could use a tool such as ImageMagick to do the conversion, e.g.

convert /tmp/test2.jpg /tmp/test2.bmp

(However: why would you use BMP? If you need lossless, consider PNG or JP2K etc.)

@sepastian Thanks for your reply.
Actually my need was to find glare percentage in image, for that i need raw image or grayscale image. is there any way to take raw image or grayscale image ?

@zain-altaf
Copy link

Hi I was wondering if this command with gst-launch is only applicable via command line or if I am able to enter this into my script that is already using gstreamer to capture an image?

@sepastian
Copy link
Author

@ramshivas same answer as above: use https://imagemagick.org/ or http://www.graphicsmagick.org/ or similar to convert a color image to b/w.

@sepastian
Copy link
Author

You can use that command inside your script @zain-altaf!

If you use the command on line 3, a single image will be captured and saved as /tmp/test.jpg.

@alex-eri
Copy link

@ramshivas , to get raw image

gst-launch-1.0 v4l2src num-buffers=1 ! videoconvert ! 'video/x-raw,width=1280,height=960,format=RGBx' ! filesink location=image.raw

Formats are listed here https://gstreamer.freedesktop.org/documentation/additional/design/mediatype-video-raw.html?gi-language=c

Threre is GRAY8, GRAY16_BE formats

@alex-eri
Copy link

Hi I was wondering if this command with gst-launch is only applicable via command line or if I am able to enter this into my script that is already using gstreamer to capture an image?

You can custumize gst pipeline or use +1 pipe with appsrc ! ... ! appsink in python scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment