Streaming images using appsrc
fgfernandez0321
fgfernandez0321 at gmail.com
Fri Feb 23 15:23:27 UTC 2018
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/
More information about the gstreamer-devel
mailing list