Gstreamer, Python and Appsink

I have a simple pipeline as shown below with Gstreamer 1.0. When I try to create app snippets, the code stops at "sample = appsink.emit (" pull-sample ")". The weird part is that if I remove that line, the code works as expected, constantly typing "try to pull the sample". I get the same cheat if I try to skip the first 100 samples or so and also change the properties to appsink. Anyone have an idea of ​​what is going on?

gst-launch-1.0 v4l2src device="/dev/video0" ! videorate ! video/x raw,height=480,width=640,framerate=15/1 !  appsink


def createASink():
    asink = Gst.ElementFactory.make('appsink', 'asink')
    asink.set_property('sync', False)
    asink.set_property('emit-signals', True)
    asink.set_property('drop', True)
    asink.connect('new-sample', new_sample)
    return asink

def new_sample(appsink):
    print "Trying to pull sample"
    sample = appsink.emit('pull-sample')
    return False

      

+3


source to share


1 answer


So, this is a workaround, but it still works. If anyone knows a better solution please let me know.

I can use fileink to output an array of bytes and then read from it continuously. I am using the multiprocessing module in python to run gstreamer and my consumer at the same time.



def consumeStream():
    fp = "gst_data"
    with open(fp, "r+b") as data_file:
        data_file.truncate()
        while True:
            where = data_file.tell()
            line = data_file.readline()
            if not line:
                time.sleep(.05)
                data_file.seek(where)
            else:
                data_file.truncate()
                print "Got data"

      

+1


source