Capturing still frames from webcam with appsink?
Tim Müller
tim at centricular.com
Sat Jan 16 08:51:42 PST 2016
On Fri, 2016-01-15 at 16:41 -0800, Matt Sarnoff wrote:
Hi Matt,
> I currently have a working C program that streams continuous frames
> from a webcam to an appsink. However, I'm only interested in
> capturing single frames when the user presses a key.
>
> In other words: when idle, the appsink receives no frames, but when a
> key is pressed, the appsink should pull a single new frame from the
> camera source.
>
> Can you point me toward example code that accomplishes this? All the
> examples I've found for still images use gst-launch-1.0 with "num-
> buffers=1". I've found that there is a delay of 1 or 2 seconds
> between the start of the pipeline and capture of the first frame, so
> I'd like to implement this without starting and stopping the pipeline
> for each capture.
There's "camerabin", which is an all-in-one element that allows you to
start/stop recording and also do single-shot capture on request via the
signals, see gst-inspect-1.0 camerabin. This might be a bit over the
top for your use case, just thought i'd mention it.
You could also do something like:
v4l2src ! fakesink
and whenever your user presses the button you do:
GstSample *sample = NULL;
g_object_get (fakesink, "last-sample", &sample, NULL);
...
gst_sample_unref (sample);
If needed, you can use gst_video_convert_sample() to convert to a
different raw format such as RGB or JPEG.
Cheers
-Tim
--
Tim Müller, Centricular Ltd - http://www.centricular.com
More information about the gstreamer-devel
mailing list