<div dir="ltr"><div><div><div><div><div><div><div><div>Hi,<br><br></div>I would like read individual frames to python/numpy for analysis. That is, I want call a function that reads and returns 1 frame. I thought I could do this with appsink, but I have 2 problems. 1) I cannot return a frame from the callback function 2) It doesn't just read 1 frame.<br><br></div>Simple example that does not do what I want:<br><br><div style="margin-left:40px">   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></div><br><div style="margin-left:40px">    CLI='filesrc location=testVideo.mp4 ! decodebin ! appsink 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></div><br></div>Is it possible to do what I want to do using appsink?<br><br></div>Another strategy I tried is to use fdsink and read the data from that location:<br><br><div style="margin-left:40px">    import os<br><br>    readfd, writefd = os.pipe() <br>    frame_size_bytes = 460800<br><br>    CLI='filesrc location=testVideo.mp4 ! decodebin ! fdsink 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></div><br></div>This does not work either. The code hang at the data = os.read... line, maybe trying to play the entire file before moving on.<br><br></div>How can I read only one frame?<br><br></div>Thanks,<br></div>Hjalmar<br></div>