79

I want to be able to take a picture using the webcam from the terminal. This image then will be saved to a file. How can this be done?

4 Answers 4

72

There is another application which can be used to capture the images from the webcam named as Fswebcam. you can install that with

sudo apt-get install fswebcam

you can have a sample shot with the following command.

fswebcam -r 640x480 --jpeg 85 -D 1 web-cam-shot.jpg

In the above code syntax , -r stands for Image resolution , --jpeg stand for format type of the image & 85 for its quality standard, -D stands for delay set before capture.

Now your image finally saved with web-cam-shot.jpg name.

Hope that helps.

5
  • 14
    In my case, my test machine, I had to skip frames to get the picture right. If I take the first frames the picture are very dark, because the camera wasn't ready yet. fswebcam -r 640x480 --jpeg 100 -D 3 -S 13 fswebcam.jpg
    – msmafra
    Feb 8, 2014 at 14:52
  • 1
    @tenshimsm I spent 10 mins figuring out what was wrong with my fswebcam and then removed the package. Installed it again just to try your approach, 30 frames worked for me. Thanks :) Jul 22, 2014 at 18:50
  • With my 5.99€ bleeding edge Sodial webcam, avconv works better.
    – Avio
    Aug 16, 2016 at 17:53
  • what I've wound helpful is: v4lctl bright 50% # apt-get install xawtv Feb 9, 2017 at 0:31
  • 4
    --no-banner (removes the bottom banner with time stamp) Feb 20, 2018 at 3:34
42

If you're looking for something automated webcam is pretty decent. It has lots of lovely options for pushing the photos over the Internet.

If you want something more manual, and we're talking about a camera supported by V4L/UVC (most of them) you can use streamer to capture a frame from the device:

streamer -f jpeg -o image.jpeg
2
  • Thanks Oli. Did not know a webcam program called WEBCAM (The irony...) existed. And yes the webcam is in the V4L supported list. Feb 23, 2012 at 0:46
  • If you get something like "neither audio nor video format specified/found" with the command streamer -f jpeg -o image.jpeg, try just streamer -o image.jpeg.
    – Moondoggy
    Dec 24, 2019 at 15:36
41

Using avconv or ffmpeg, you can capture a frame from your device as well. For example:

avconv -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 /tmp/out.jpg

or

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 /tmp/out.jpg

This will open /dev/video0 as a video4linux2 compatible device, set up resolution to 640x480, stream for 2 seconds (00:00:02 or simply 2), then capture one single frame, saving it to /tmp/out.jpg.

Check if your device is /dev/video0, as it can be different for you.

The available resolutions depend on your webcam. Mine goes up to 640x480 and I checked it with a tool called qv4l2, which is used to configure a video4linux2 device.

The -ss parameter is used to allow the device to start up correctly. Here in my tests, there is a fade-in effect while the camera is being turned on, so, if I just omit -ss 2, the captured frame will be very dark.

2
  • 2
    I preferred this solution as I'd already installed avconv. Also, the output of avconv also gives hints to the maximum resolution, as the v4l driver shows if it has to fall back onto a lower specification.
    – icedwater
    Sep 20, 2018 at 16:31
  • I use this because FFMpeg gave me better quality than the other options.
    – ThoriumBR
    Dec 10, 2023 at 18:40
11

You can also try uvccapture.

uvccapture -m

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .