Can not get right data from appsink in python
Matthew Waters
ystreet00 at gmail.com
Fri Jan 12 03:10:14 UTC 2018
On 12/01/18 12:56, Yawei Wang wrote:
> 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)
This needs to be in the while loop below.
What the code currently says is:
1. Pull one sample
2. While true, get the buffer from the sample (this will always return
the same buffer).
What you want is to pull_sample() inside the while loop
> 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/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 516 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20180112/9d8fafd8/attachment.sig>
More information about the gstreamer-devel
mailing list