Advertisement
Guest User

Untitled

a guest
Apr 10th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. import sys, time, copy
  2. import gi
  3. gi.require_version('Gst', '1.0')
  4. from gi.repository import GObject, Gst, GstVideo, Gtk
  5. GObject.threads_init()
  6. Gst.init(None)
  7.  
  8. class Player():
  9.     def __init__(self):
  10.  
  11.         # build pipeline
  12.         self.pipeline = Gst.ElementFactory.make('pipeline',"pipeline")
  13.         self.source = Gst.ElementFactory.make('videotestsrc')
  14.         self.capsfilter = Gst.ElementFactory.make('capsfilter')
  15.         self.sink = Gst.ElementFactory.make('xvimagesink')
  16.         self.pipeline.add(self.source)
  17.         self.pipeline.add(self.capsfilter)
  18.         self.pipeline.add(self.sink)
  19.         self.source.link(self.capsfilter)
  20.         self.capsfilter.link(self.sink)
  21.         self.capsfilter.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, self.cbBufferAtSource)
  22.         self.capsfilter.set_property("caps", Gst.caps_from_string("video/x-raw,width=320,height=240,framerate=(fraction)1/1,format=I420"))
  23.         self.pipeline.set_state(Gst.State.PLAYING)
  24.  
  25.     def cbBufferAtSource(self, argElement, argPadProbeInfo):
  26.         buffer = argPadProbeInfo.get_buffer()
  27.         print "Received a buffer (pts: %d). Adding metadata!" % (buffer.pts)
  28.         # Get a fresh VideoCropMeta struct
  29.         videoCropMetaInstance = GstVideo.VideoCropMeta()
  30.         # Using the next statement we can see that GstVideo.VideoCropMeta() is indeed the proper struct exposing x, y, width, height as expected.
  31.         #print dir(videoCropMetaInstance)
  32.         videoCropMetaInstance.x = 20
  33.         videoCropMetaInstance.y = 20
  34.         videoCropMetaInstance.width = 20
  35.         videoCropMetaInstance.height = 20
  36.         # Get Gst.MetaInfo from GstVideoCropMeta instance
  37.         videoCropMetaInstanceInfo = videoCropMetaInstance.get_info()
  38.         # Add metadata to buffer
  39.         meta = buffer.add_meta(videoCropMetaInstanceInfo, 0)
  40.         # Print our tags which read correctly: ['video', 'size', 'orientation']
  41.         print "API tags: ", meta.api_type_get_tags(videoCropMetaInstanceInfo.api)
  42.         # Print the memory address of our metadata and the type (Gst.Meta)
  43.         print "Gst.Meta memory address: ", meta
  44.         print "Type of meta:", type(meta)
  45.         # Try to get back our Gst.Meta from our buffer
  46.         test = (buffer.get_meta(videoCropMetaInstanceInfo.api))
  47.         print "Gst.Meta memory address recovered from GstBuffer: ", test
  48.         # How to proceed from here?
  49.         # Set .x and .y on meta? That doesn't work
  50.         print "*"*30
  51.         return Gst.PadProbeReturn.OK
  52.  
  53. if __name__ == '__main__':
  54.     GObject.threads_init()
  55.     Player()
  56.     while(True):
  57.         Gtk.main_iteration_do(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement