GstBuffer to numpy conversion

Peter Rennert p.rennert at
Mon Dec 17 11:52:03 PST 2012

I am using gstreamer 0.10 with python bindings.

I want to convert a gst buffer into a numpy array. Online I found only 
examples [1] for audio and they are using

import pygst
import gst
import gobject
import numpy as np

def getBuffer(buf):
     array = np.fromBuffer(, dtype=float32)
     return array

Which is clearly not correct for video frames. Normally I would expect a 
datatype like uchar. In my C++ code I used guint8 which I got from some 
reference online.

However, if I try in python dtype=np.uint8 or dtype="I" (for c-uint8) or 
"B" (for c-uchar) [2], I get some data,  but I am not getting a proper 
length of my array. I am expecting a frame of 1920x1080x3 = 6220800 
pixels. My  buffers are too short. Using "B", I get only an array of 
length 3110400, which is strangely half of what I would expect 
(1920x1080x1.5 (!)).

Has anyone done a conversion from gst-buffers to python? Or an idea what 
I could try?



More information about the gstreamer-devel mailing list