2014-09-10 48 views
1

在舊的(Pre-GObject-introspection)GStreamer綁定中,可以通過.data屬性訪問gst.Buffer數據,或者鑄造到str。這不再是可能的:如何在Python中訪問GStreamer緩衝區的數據?

>>> p buf.data 
*** AttributeError: 'Buffer' object has no attribute 'data' 
>>> str(buf) 
'<GstBuffer at 0x7fca2c7c2950>' 

回答

4

要訪問最近版本Gst.Buffer的內容,你必須先map()緩衝區得到Gst.MapInfo,其中有bytes類型的data屬性(str在Python 2)。

(result, mapinfo) = buf.map(Gst.MapFlags.READ) 
assert result 

try: 
    # use mapinfo.data here 
    pass 
finally: 
    buf.unmap(mapinfo) 

您還可以get_memory()訪問緩衝區組成Gst.Memory元素,並分別將它們映射。 (AFAICT,主叫Buffer.map()相當於調用.get_all_memory()和映射所得Memory。)

不幸的是,寫入這些緩衝區是不可能的,因爲Python的表示它們與即使當Gst.MapFlags.WRITE標誌被設置不變類型。相反,您必須執行以下操作:使用修改的數據創建新的Gst.Memory,並使用Gst.Buffer.replace_all_memory()

+0

如果您的目標是CentOS 7,那麼隨附的gi綁定不夠完善,但這裏有一個解決方法:https://bugzilla.gnome.org/show_bug.cgi?id = 678663#C73 – totaam 2015-12-28 11:49:12

相關問題