<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Date: Sat, 16 Jan 2016 16:51:42 +0000<br>
From: Tim Müller <<a href="mailto:tim@centricular.com">tim@centricular.com</a>><br>
To: <a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br>
Subject: Re: Capturing still frames from webcam with appsink?<br>
Message-ID: <<a href="mailto:1452963102.21646.17.camel@centricular.com">1452963102.21646.17.camel@centricular.com</a>><br>
Content-Type: text/plain; charset="UTF-8"<br><br>
You could also do something like:<br>
<br>
 v4l2src ! fakesink<br>
<br>
and whenever your user presses the button you do:<br>
<br>
 GstSample *sample = NULL;<br>
<br>
 g_object_get (fakesink, "last-sample", &sample, NULL);<br>
 ...<br>
 gst_sample_unref (sample);<br>
<br>
If needed, you can use gst_video_convert_sample() to convert to a<br>
different raw format such as RGB or JPEG.<br></blockquote><div><br></div><div>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?</div><div><br></div><div>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:</div><div><br></div><div>g_object_set(output_selector, "active-pad", bayer2rgb_src_pad, NULL);</div><div>GstSample *sample = gst_app_sink_pull_sample(appsink);</div><div><div>g_object_set(output_selector, "active-pad", fakesink_src_pad, NULL);</div></div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Thanks!</div><div>-matt</div></div></div></div>