Can not get right data from appsink in python

Yawei Wang wangyawei_dlut at 163.com
Fri Jan 12 01:56:27 UTC 2018


I use python to get data from appsink. My code is like below:
```
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstApp', '1.0')
from gi.repository import GObject, Gst, GstApp

GObject.threads_init()
Gst.init(None)


class Example:
    def __init__(self):
        self.mainloop = GObject.MainLoop()
        self.pipeline = Gst.Pipeline()
        self.bus = self.pipeline.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect('message::eos', self.on_eos)
        self.bus.connect('message::error', self.on_error)

        # Create elements
        self.src = Gst.ElementFactory.make('v4l2src', None)
        self.encoder = Gst.ElementFactory.make('x264enc', None)
        self.parse = Gst.ElementFactory.make('h264parse', None)
        self.mux = Gst.ElementFactory.make('flvmux', None)
        self.sink = Gst.ElementFactory.make('appsink', None)

        # Add elements to pipeline
        self.pipeline.add(self.src)
        self.pipeline.add(self.encoder)
        self.pipeline.add(self.parse)
        self.pipeline.add(self.mux)
        self.pipeline.add(self.sink)

        # Set properties
        self.src.set_property('device', "/dev/video0")

        # Link elements
        self.src.link(self.encoder)
        self.encoder.link(self.parse)
        self.parse.link(self.mux)
        self.mux.link(self.sink)

    def run(self):
        self.pipeline.set_state(Gst.State.PLAYING)
        # self.mainloop.run()
        appsink_sample = GstApp.AppSink.pull_sample(self.sink)
        while True:
            buff = appsink_sample.get_buffer()
            size, offset, maxsize = buff.get_sizes()
            frame_data = buff.extract_dup(offset, size)
            print(frame_data)

    def kill(self):
        self.pipeline.set_state(Gst.State.NULL)
        self.mainloop.quit()

    def on_eos(self, bus, msg):
        print('on_eos()')
        self.kill()

    def on_error(self, bus, msg):
        print('on_error():', msg.parse_error())
        self.kill()


example = Example()
example.run()
```

But I got the same data like "FLV\0x01\0x01". Someone could answer the
question?



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list