Package timeside :: Package tools :: Module gstutils
[hide private]
[frames] | no frames]

Source Code for Module timeside.tools.gstutils

 1  from numpy import array, getbuffer, frombuffer 
 2   
 3  import pygst 
 4  pygst.require('0.10') 
 5  import gst 
 6  import gobject 
 7  gobject.threads_init() 
 8   
 9   
10 -def numpy_array_to_gst_buffer(frames, CHUNK_SIZE, num_samples, SAMPLE_RATE):
11 from gst import Buffer 12 """ gstreamer buffer to numpy array conversion """ 13 buf = Buffer(getbuffer(frames.astype("float32"))) 14 #Set its timestamp and duration 15 buf.timestamp = gst.util_uint64_scale(num_samples, gst.SECOND, SAMPLE_RATE) 16 buf.duration = gst.util_uint64_scale(CHUNK_SIZE, gst.SECOND, SAMPLE_RATE) 17 18 return buf
19 20
21 -def gst_buffer_to_numpy_array(buf, chan):
22 """ gstreamer buffer to numpy array conversion """ 23 samples = frombuffer(buf.data, dtype='float32') 24 samples.resize([len(samples)/chan, chan]) 25 return samples
26