Capturing still frames from webcam with appsink?
Matt Sarnoff
matt.sarnoff at gmail.com
Mon Jan 18 09:59:48 PST 2016
>
> Date: Sat, 16 Jan 2016 16:51:42 +0000
> From: Tim Müller <tim at centricular.com>
> To: gstreamer-devel at lists.freedesktop.org
> Subject: Re: Capturing still frames from webcam with appsink?
> Message-ID: <1452963102.21646.17.camel at centricular.com>
> Content-Type: text/plain; charset="UTF-8"
>
> 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.
>
Interesting. My camera only outputs raw Bayer data, so my pipeline looks
like "v4l2src ! bayer2rgb ! jpegenc ! appsink". I don't want to do the
Bayer/JPEG conversion for the frames I don't care about--if I removed those
elements from the pipeline, could I use gst_video_convert_sample() to
convert Bayer->JPEG in one go?
My current solution involves using an output_selector element as a "valve."
When idle, the output_selector connects v4l2src to a fakesink. When I want
to capture a frame, I change the "active-pad" property of the
output_selector and pull a frame:
g_object_set(output_selector, "active-pad", bayer2rgb_src_pad, NULL);
GstSample *sample = gst_app_sink_pull_sample(appsink);
g_object_set(output_selector, "active-pad", fakesink_src_pad, NULL);
This appeared to work, but I was finding that sometimes (as frequently as
every other capture) gst_app_sink_pull_sample() was returning a stale
frame, i.e. more than one frame was making its way through the
output_selector while it was "open," and an extra frame from the previous
capture request was stuck in the queue.
My guess was that it was a threading issue, so I moved the
g_object_set("active-pad", fake_src_pad) call to the appsink's new_sample
callback. This seems to have solved the issue, but the entire solution
seems a bit complicated.
Thanks!
-matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20160118/a3ace8d3/attachment.html>
More information about the gstreamer-devel
mailing list