I have this example in python where I want to stream images via UDP. In this
case I'm testing using autovideosink in order to know how the images change. Based on the documentation I need to free the buffer when it is used however I haven't found a function on Python bindings to solve this. I tried to use "push_buffer" function instead of signals but it is not exist at least in my version. At this point, when the first images is shown, I can't push more buffers because "enough-data" signal is emitted and "need-data" is not emitted again in order to start push buffers. Could you please help me to clarify me? Thank you class SenderImages: def __init__(self): # Control if it is allowed push buffer in queue using "need-data" and "enough-data" signals self.is_push_buffer_allowed = None self._mainloop = GObject.MainLoop() auto_video_sink_pipeline = "appsrc name=source ! decodebin ! imagefreeze ! autovideosink" self._pipeline = Gst.parse_launch(auto_video_sink_pipeline) # udp_sink_pipeline = "appsrc name=source ! decodebin ! imagefreeze ! udpsink host=localhost port=55100" # self._pipeline = Gst.parse_launch(udp_sink_pipeline) self._src = self._pipeline.get_by_name('source') self._src.connect('need-data', self.start_feed) self._src.connect('enough-data', self.stop_feed) # length is just a hint and when it is set to -1, any number of bytes can be pushed into appsrc # self._src.set_property("length", -1) def start_feed(self, src, length): print('======================> need data length: %s' % length) self.is_push_buffer_allowed = True def stop_feed(self, src): print('======================> enough_data') self.is_push_buffer_allowed = False def play(self): self._pipeline.set_state(Gst.State.PLAYING) def stop(self): self._pipeline.set_state(Gst.State.NULL) def run(self): """ Run - blocking. """ self._mainloop.run() def push(self): """ Push a buffer into the source. """ if self.is_push_buffer_allowed: image_number = randint(1, 4) filename = 'images/%s.jpg' % image_number img = PILImage.open(filename, mode='r') img_byte_array = io.BytesIO() img.save(img_byte_array, format='JPEG') img_byte_array = img_byte_array.getvalue() buffer = Gst.Buffer.new_wrapped(img_byte_array) # Push the buffer into the appsrc gst_flow_return = self._src.emit('push-buffer', buffer) # gst_flow_return = self._src.push_buffer(buffer) # Free the buffer now that we are done with it # Do something # Not function found to unref buffer if gst_flow_return != Gst.FlowReturn.OK: print('We got some error, stop sending data') else: print('It is enough data for buffer....') gst_app_src = SenderImages() gst_app_src.play() index = 0 while index < 1000: print('========================= Showing picture...') gst_app_src.push() time.sleep(1) index += 1 -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Couple of pointers:
1. you don't need to explicitly free the buffers when using Python. 2. Set the caps on your appsrc element: "image/jpeg,framerate=30/1" 3. Set 'format' = 'bytes' property and 'do-timestamp' = 'true' on appsrc 4. emit("push-sample", sample) is the way to go 5. add a queue between appsrc and decodebin. -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi Arjen,
Thank you for your help. I followed your steps however not working as expected. At the end, what I would like to achieve is to show the images using autovideosink as video playing but using images instead of a video with frames... I send you a zip with the source just in case you need it. SenderImages.zip <http://gstreamer-devel.966125.n4.nabble.com/file/t377167/SenderImages.zip> Regards This the code based on your explanation: from PIL import Image as PILImage from random import randint import time import gi import io gi.require_version('Gst', '1.0') gi.require_version('GstApp', '1.0') gi.require_version('Gtk', '3.0') # noinspection PyUnresolvedReferences from gi.repository import GObject, Gst, Gtk GObject.threads_init() Gst.init(None) class SenderImages: def __init__(self): # Control if it is allowed push buffer in queue using "need-data" and "enough-data" signals self.is_push_buffer_allowed = None self._mainloop = GObject.MainLoop() auto_video_sink_pipeline = "appsrc name=source ! image/jpeg,framerate=30/1 ! queue ! decodebin ! imagefreeze ! autovideosink" self._pipeline = Gst.parse_launch(auto_video_sink_pipeline) self._src = self._pipeline.get_by_name('source') self._src.connect('need-data', self.start_feed) self._src.connect('enough-data', self.stop_feed) self._src.set_property('format', 'bytes') self._src.set_property('do-timestamp', 'true') # GstBase.BaseSrc def start_feed(self, src, length): print('======================> need data length: %s' % length) self.is_push_buffer_allowed = True def stop_feed(self, src): print('======================> enough_data') self.is_push_buffer_allowed = False def play(self): self._pipeline.set_state(Gst.State.PLAYING) def stop(self): self._pipeline.set_state(Gst.State.NULL) def run(self): """ Run - blocking. """ self._mainloop.run() def push(self): """ Push a buffer into the source. """ if self.is_push_buffer_allowed: image_number = randint(1, 4) filename = 'images/%s.jpg' % image_number img = PILImage.open(filename, mode='r') img_byte_array = io.BytesIO() img.save(img_byte_array, format='JPEG') img_byte_array = img_byte_array.getvalue() buffer = Gst.Buffer.new_wrapped(img_byte_array) gst_sample = Gst.Sample.new(buffer) gst_flow_return = self._src.emit('push-sample', gst_sample) if gst_flow_return != Gst.FlowReturn.OK: print('We got some error, stop sending data') else: print('It is enough data for buffer....') sender = SenderImages() sender.play() index = 0 while index < 1000: print('========================= Showing picture...') sender.push() time.sleep(1) index += 1 -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
This should get you going:
https://gist.github.com/arjenveenhuizen/00959940296e03c40fb9cf0087f6116d -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi Arjen,
It is working. Thank you -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |