In the old (pre-GObject-introspection) GStreamer bindings, it was possible to access gst.Buffer
data via the .data
attribute or by casting to str
. This is no longer possible:
>>> p buf.data
*** AttributeError: 'Buffer' object has no attribute 'data'
>>> str(buf)
'<GstBuffer at 0x7fca2c7c2950>'
To access the contents of a Gst.Buffer
in recent versions, you must first map()
the buffer to get a Gst.MapInfo
, which has a data
attribute of type bytes
(str
in Python 2).
(result, mapinfo) = buf.map(Gst.MapFlags.READ)
assert result
try:
# use mapinfo.data here
pass
finally:
buf.unmap(mapinfo)
You can also access the buffer's constituent Gst.Memory
elements with get_memory()
, and map them individually. (AFAICT, calling Buffer.map()
is equivalent to calling .get_all_memory()
and mapping the resulting Memory
.)
Unfortunately, writing to these buffers is not possible since Python represents them with immutable types even when the Gst.MapFlags.WRITE
flag is set. Instead, you'd have to do something like create a new Gst.Memory
with the modified data, and use Gst.Buffer.replace_all_memory()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With