Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time, copy
- import gi
- gi.require_version('Gst', '1.0')
- from gi.repository import GObject, Gst, GstVideo, Gtk
- GObject.threads_init()
- Gst.init(None)
- class Player():
- def __init__(self):
- # build pipeline
- self.pipeline = Gst.ElementFactory.make('pipeline',"pipeline")
- self.source = Gst.ElementFactory.make('videotestsrc')
- self.capsfilter = Gst.ElementFactory.make('capsfilter')
- self.sink = Gst.ElementFactory.make('xvimagesink')
- self.pipeline.add(self.source)
- self.pipeline.add(self.capsfilter)
- self.pipeline.add(self.sink)
- self.source.link(self.capsfilter)
- self.capsfilter.link(self.sink)
- self.capsfilter.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, self.cbBufferAtSource)
- self.capsfilter.set_property("caps", Gst.caps_from_string("video/x-raw,width=320,height=240,framerate=(fraction)1/1,format=I420"))
- self.pipeline.set_state(Gst.State.PLAYING)
- def cbBufferAtSource(self, argElement, argPadProbeInfo):
- buffer = argPadProbeInfo.get_buffer()
- print "Received a buffer (pts: %d). Adding metadata!" % (buffer.pts)
- # Get a fresh VideoCropMeta struct
- videoCropMetaInstance = GstVideo.VideoCropMeta()
- # Using the next statement we can see that GstVideo.VideoCropMeta() is indeed the proper struct exposing x, y, width, height as expected.
- #print dir(videoCropMetaInstance)
- videoCropMetaInstance.x = 20
- videoCropMetaInstance.y = 20
- videoCropMetaInstance.width = 20
- videoCropMetaInstance.height = 20
- # Get Gst.MetaInfo from GstVideoCropMeta instance
- videoCropMetaInstanceInfo = videoCropMetaInstance.get_info()
- # Add metadata to buffer
- meta = buffer.add_meta(videoCropMetaInstanceInfo, 0)
- # Print our tags which read correctly: ['video', 'size', 'orientation']
- print "API tags: ", meta.api_type_get_tags(videoCropMetaInstanceInfo.api)
- # Print the memory address of our metadata and the type (Gst.Meta)
- print "Gst.Meta memory address: ", meta
- print "Type of meta:", type(meta)
- # Try to get back our Gst.Meta from our buffer
- test = (buffer.get_meta(videoCropMetaInstanceInfo.api))
- print "Gst.Meta memory address recovered from GstBuffer: ", test
- # How to proceed from here?
- # Set .x and .y on meta? That doesn't work
- print "*"*30
- return Gst.PadProbeReturn.OK
- if __name__ == '__main__':
- GObject.threads_init()
- Player()
- while(True):
- Gtk.main_iteration_do(True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement