<div dir="ltr"><div><div><div><div>Hi,<br><br>In general, it seems that things fail with Format.BUFFERS while it works with Format.TIME.<br><br></div>For example:<br><br><div style="margin-left:40px">In [13]: pipeline.query_duration(Gst.Format.BUFFERS)<br></div><div style="margin-left:40px">Out[13]: (False, 0)<br></div><br></div>While this works fine:<br><div style="margin-left:40px">In [14]: pipeline.query_duration(Gst.Format.TIME)<br>Out[14]: (True, 889267000000)<br><br></div>Format.BUFFERS looks otherwise ok:<br><br><div style="margin-left:40px">In [15]: Gst.Format.BUFFERS<br>Out[15]: <enum GST_FORMAT_BUFFERS of type GstFormat><br><br></div>Maybe I messed up something obvious. Using version 1.6.0.0<br><br></div>Thanks,<br></div>Hjalmar<br><div><div><div><div><div><div style="margin-left:40px"><br><br></div><br><div><div><div><div style="margin-left:40px"><br></div><br><div><br><br><div><div><div style="margin-left:40px"><div style="margin-left:40px"><br></div></div><div><div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 6:01 PM, Hjalmar Turesson <span dir="ltr"><<a href="mailto:hturesson@gmail.com" target="_blank">hturesson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi,<br><br></div>The seek works when the format is TIME, e.g.:<br><br><div style="margin-left:40px">pipeline.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0.3*Gst.SECOND)<br><br></div>but not when the format is BUFFERS, e.g.:<br><br><div style="margin-left:40px">pipeline.seek_simple(Gst.Format.BUFFERS, Gst.SeekFlags.FLUSH, 1000)<br><br></div>Does this make any sense?<br><br></div>Thanks,<br></div>Hjalmar<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 4:07 PM, Hjalmar Turesson <span dir="ltr"><<a href="mailto:hturesson@gmail.com" target="_blank">hturesson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Perfect example. It does exactly what I wanted.<br><br>But... The seek returns false (the other part works perfectly)<br><br><div style="margin-left:40px">    CLI='filesrc location=%s ! decodebin ! appsink name=sink' % filename<br>    pipeline=Gst.parse_launch(CLI)<br>    # get sink<br>    appsink=pipeline.get_by_name("sink")<br>    # set to PAUSED to make the first frame arrive in the sink<br>    pipeline.set_state(Gst.State.PAUSED)<br><b>    pipeline.seek_simple(Gst.Format.BUFFERS, Gst.SeekFlags.FLUSH, frame_number)</b><br>    smp = appsink.emit('pull-preroll')<br>    buf = smp.get_buffer()<br><br>    data=buf.extract_dup(0, buf.get_size())[:307200] # Only 1/2 of expected RGB size<br>    frame = np.fromstring(data,dtype='uint8').reshape((480,640,1))<br><br><br></div>Thanks a lot,<br><br></div>Hjalmar<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 1:47 PM, Tim Müller <span dir="ltr"><<a href="mailto:tim@centricular.com" target="_blank">tim@centricular.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, 2015-12-07 at 13:30 -0300, Hjalmar Turesson wrote:<br>
<br>
Hi Hjalmar,<br>
<br>
This (C) example shows how to retrieve frames from appsink, perhaps you<br>
find it useful:<br>
<br>
<a href="http://cgit.freedesktop.org/gstreamer/gst-plugins-base/tree/tests/examples/snapshot/snapshot.c" rel="noreferrer" target="_blank">http://cgit.freedesktop.org/gstreamer/gst-plugins-base/tree/tests/examp<br>
les/snapshot/snapshot.c</a><br>
<br>
It uses the pull-preroll signal/API, that only works once, if you want<br>
to retrieve one frame, and then another one, then just use the pull-<br>
sample API N times.<br>
<br>
There are two ways to use appsink: one is to have it emit a signal<br>
(new-sample) whenever a buffer arrives, and then you pull it in the<br>
callback). The other is to simply set the pipeline to PLAYING and then<br>
do pull-sample, which will block and wait for a simple if none is<br>
available yet then.<br>
<br>
Note that from the "new-sample" signal callback you can also return<br>
GST_FLOW_EOS if you don't want to be called again.<br>
<br>
Cheers<br>
 -Tim<br>
<div><div><br>
> Hi,<br>
><br>
> I would like read individual frames to python/numpy for analysis.<br>
> That is, I want call a function that reads and returns 1 frame. I<br>
> thought I could do this with appsink, but I have 2 problems. 1) I<br>
> cannot return a frame from the callback function 2) It doesn't just<br>
> read 1 frame.<br>
><br>
> Simple example that does not do what I want:<br>
><br>
>    import gi<br>
>    gi.require_version('Gst', '1.0')<br>
>    from gi.repository import GObject, Gst, Gtk<br>
>    GObject.threads_init()<br>
>    Gst.init(None)<br>
>    ##########<br>
><br>
>     CLI='filesrc location=testVideo.mp4 ! decodebin ! appsink<br>
> name=sink'<br>
>     pipeline=Gst.parse_launch(CLI)<br>
>     appsink=pipeline.get_by_name("sink")<br>
>     appsink.set_property("max-buffers",1)<br>
>     appsink.set_property('emit-signals',True)<br>
>     appsink.set_property('sync',False)<br>
>    <br>
>     def on_new_buffer(appsink):<br>
>         sample = appsink.emit('pull-sample')<br>
>         #get the buffer<br>
>         buf=sample.get_buffer()<br>
>         data=buf.extract_dup(0,buf.get_size())<br>
>         return False  # Here I would like to return the frame<br>
><br>
>     appsink.connect('new-sample', on_new_buffer)<br>
>     pipeline.set_state(Gst.State.PLAYING)<br>
>     pipeline.set_state(Gst.State.NULL)<br>
><br>
> Is it possible to do what I want to do using appsink?<br>
><br>
> Another strategy I tried is to use fdsink and read the data from that<br>
> location:<br>
><br>
>     import os<br>
><br>
>     readfd, writefd = os.pipe()<br>
>     frame_size_bytes = 460800<br>
><br>
>     CLI='filesrc location=testVideo.mp4 ! decodebin ! fdsink<br>
> name=sink'   <br>
>     pipeline=Gst.parse_launch(CLI)<br>
>     fdsink=pipeline.get_by_name("sink")<br>
>     fdsink.set_property("fd", readfd)<br>
><br>
>     pipeline.set_state(Gst.State.PLAYING)<br>
>     data = os.read(readfd, frame_size_bytes)<br>
>     pipeline.set_state(Gst.State.PAUSED)<br>
><br>
> This does not work either. The code hang at the data = os.read...<br>
> line, maybe trying to play the entire file before moving on.<br>
><br>
> How can I read only one frame?<br>
><br>
> Thanks,<br>
> Hjalmar<br>
</div></div>> _______________________________________________<br>
> gstreamer-devel mailing list<br>
> <a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
<span><font color="#888888">--<br>
Tim Müller, Centricular Ltd - <a href="http://www.centricular.com" rel="noreferrer" target="_blank">http://www.centricular.com</a><br>
<br>
<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>