3
1
I am looking for a command-line tool that can take a picture from a webcam as fast as possible and write it to stdout. In addition, I would like to be able to specify settings like input format, resolution and output format.
My first try was ffmpeg:
ffmpeg -f video4linux2 -video_size 1920x1080 -input_format yuyv422 -i /dev/video0 -f image2 -frames:v 1 -qscale:v 2 pipe:1
However, this has two drawbacks:
It takes about 3 seconds until the image is written to stdout, which seems to be due to the time the webcam needs to initialize.
The picture taken this way is rather dark, probably the webcam needs to capture a view video frames to adjust brightness etc..
My next idea is to continuously capture video frames from the webcam (i.e. "keep the webcam active"), stream these video frames somewhere, and then grab single video frames and convert them to an image on demand. However, I do not know how to do this (and if there is a better way).
EDIT: I need a one-off command that writes the image to stdout, so I can use it in a http server to serve a http GET request. It needs to be quick, because taking the picture is blocking a mechanical process in a machine.
1For the "minimal delay" you can also send signal SIGUSR1 to fswebcam to have it capture immediately, when it is in timed loop mode. – meuh – 2017-09-20T20:00:02.087
1Thank you dirkt and @meuh. I updated my question to explain why I need this. I see now that my webcam is simply slow when getting the first picture. I will see if using fswebcam with the loop option in combination with SIGUSR1 helps. I found another solution (I'll post it here), but it is also not optimal (it lowers the cameras fps). – x-ray – 2017-09-20T22:31:38.437
Did you find a way to take pictures fast ? – razor – 2019-04-02T09:45:00.880