How to capture a still image from a V4L2 UVC webcam?
The question here is how to capture a JPEG still image from a V4L2 (Video for Linux 2) webcam, using Linux tools. The webcam in question is a Creative Live!Cam Optia; because it is a UVC (USB video class) compatible camera, the solution should at least work with all other UVC webcams, too.
Working alternative
Instructions
The only working alternative is, for now, to use gstreamer (to show the stream) and a screenshot tool. You cannot use all video sinks, as some are not accessible to the screenshot tools. What can be captured by the screenshot tools is the “ximagesink” video sink. How to do it:
Execute this command in a terminal while your webcam is connected:
Now in another terminal, create a screenshot by executing the commandscrot.
You may now write a script that gets a screenshot like this and handles / processes it, like uploading to a server.
Background Infos
To test things about gstreamer and screenshots, you can also use the test video source for testing. The following worked for creating screenshots like above:
gst-launch videotestsrc ! queue ! ximagesink
In my tests, the following video sinks did not work to create screenshots like above:
You may use gstreamer to take the screenshots. A webcam that serves JPEG images just serves JPEG images one after the other. The following worked to view the first captured image from a file that contains JPEG after JPEG:
gst-launch v4l2src ! filesink location=file.jpg
kuickshow file.jpg
This is even a very promising path, as you can combine some JPGs to reduce the noise.
Use gstreamer to pipe to vlc
You may use gstreamer with a filesink and then pipe that to vlc. The following created basic screen output here:
(This however makes xine not recognize the format.)
And now, piping to vlc media player is possible by:
gst-launch v4l2src ! avimux ! fdsink | vlc -
(But this is not possible yet.) (You may need the “ffmpegcolorspace” element, it’s important.) (See here for the documentation: http://wiki.videolan.org/Uncommon_uses.)
Something comparable should be possible with xine:
gstreamer is no alternative as it was impossible to create a network stream from it.
uvc-streamer
It is possible to use UVC-Streamer ( http://naaa.de/uvc_streamer.htm ), which works for V4L2 devices; however there were compilation errors.
mjpeg-streamer
It is possible to use MJPEG-Streamer, which is the successor to UVC-Streamer; however, compile errors happened in both the 35 and 51 revisions.
uvccapture
It is possible to use uvccapture; however, this is rather a hack and has errors when compiling.
MPEG4IP
MPEG4IP might be a possibility, but their tarball is corrupt and their development stopped.
ucview
You may try ucview (an application based on the unicap framework). There are .debs available; however, I wasn’t able to get an image (though it supports MJPEG); it would be the most comfortable software for capturing selected frames.
Автоюристы в СПб —
защита прав клиентов в соответствии с практикой Леноблсуда.
Результаты за 2023-2024 гг:
✔ 92% дел по оспариванию штрафов – в пользу клиентов
✔ 120+ успешных кейсов по оспариванию штрафов с камер
✔ 85% страховых споров – решено досудебно
Примеры решений:
– Анализ схем ДТП на Невском проспекте
– Возврат Изьятого авто со штрафстоянки
Leave a Reply