Dear group,
is it possible to use the python bindings to create a source plugin? I imagine something closely related to the imagefreeze plugin: - behave like imagefreeze most of the time (serve static image at specified fps) - change image whenever new image arrives from somewhere else within my (python) code. Thanks! Mathias _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi,
is it possible to use the python bindings to create a source plugin? just yesterday i faced with same question. And i don't know how, but at first i lost from view most obvious place of getting information, this is: - http://cgit.freedesktop.org/gstreamer/gst-python/tree/examples/filesrc.py But fortunately i found next few very helpful links: - http://guillaume.segu.in/blog/code/223/useful-paralellism-with-python/ - http://nullege.com/codes/search/gst.PushSrc - http://svn.annodex.net/keystroke/trunk/textsrc.py So basically you have to inherit from BaseSrc or PushSrc and implement do_create method. If your source support seeking than few other also. On debian testing/unstable PushSrc seems not available in python-gst package so i inherited BaseSrc. I imagine something closely related to the imagefreeze plugin: Can't say something here, you may be need to give close attention to clocks in gstreamer to source at specific fps. Will be glad to hear how you do this if you will figure this out, - change image whenever new image arrives from somewhere else withinYou just need to update you source buffer passed through do_create function. Here is my code to push text string through udp (this like a little bit simplified version of filesrc example). """ Source buf """ # -*- Mode: Python -*- # vi:si:et:sw=4:sts=4:ts=4 # import gobject gobject.threads_init() import pygst pygst.require('0.10') import gst class Bufsrc(gst.BaseSrc): """ Push text """ #here we register our plugin details __gstdetails__ = ( "bufsrc test plugin", "bufsrc.py", "Source element that create a buffer", "Oleksandr Lavrushchenko <____@gmail.com>") _src_template = gst.PadTemplate ("src", gst.PAD_SRC, gst.PAD_ALWAYS, gst.caps_new_any ()) __gsttemplates__ = (_src_template,) def __init__ (self, *args, **kwargs): gst.BaseSrc.__init__(self) gst.info('creating srcpad') self.src_pad = gst.Pad (self._src_template) self.src_pad.use_fixed_caps() #self.add_pad (self.src_pad) def do_create(self, offset, length): buf = gst.Buffer("data\n") buf.timestamp = 0 buf.duration = pow(2, 63) -1 return gst.FLOW_OK, buf # Register element class gobject.type_register(Bufsrc) gst.element_register(Bufsrc, 'bufsrc', gst.RANK_MARGINAL) sink = gst.element_factory_make("udpsink", "sink") sink.set_property("port", 5000) sink.set_property("host", "127.0.0.1") pusher = Bufsrc() player = gst.Pipeline("player") player.add(pusher, sink) gst.element_link_many(pusher2, sink) player.set_state(gst.STATE_PLAYING) gobject.MainLoop().run() _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Just out of curiosity:
Why python and not C or Vala? On Thu, Jul 7, 2011 at 3:46 PM, Oleksandr Lavrushchenko <[hidden email]> wrote: > Hi, > >> is it possible to use the python bindings to create a source plugin? > > just yesterday i faced with same question. > And i don't know how, but at first i lost from view most obvious place of > getting information, this is: > > - http://cgit.freedesktop.org/gstreamer/gst-python/tree/examples/filesrc.py > > But fortunately i found next few very helpful links: > > - http://guillaume.segu.in/blog/code/223/useful-paralellism-with-python/ > - http://nullege.com/codes/search/gst.PushSrc > - http://svn.annodex.net/keystroke/trunk/textsrc.py > > So basically you have to inherit from BaseSrc or PushSrc and implement > do_create method. If your source support seeking than few other also. > > On debian testing/unstable PushSrc seems not available in python-gst package > so i inherited BaseSrc. > >> I imagine something closely related to the imagefreeze plugin: >> - behave like imagefreeze most of the time (serve static image at >> specified fps) > > Can't say something here, you may be need to give close attention to clocks > in gstreamer to source at specific fps. Will be glad to hear how you do this > if you will figure this out, > >> - change image whenever new image arrives from somewhere else within >> my (python) code. > > You just need to update you source buffer passed through do_create function. > > Here is my code to push text string through udp (this like a little bit > simplified version of filesrc example). > > #!/usr/bin/env python > """ Source buf """ > # -*- Mode: Python -*- > # vi:si:et:sw=4:sts=4:ts=4 > # > > import gobject > gobject.threads_init() > > import pygst > pygst.require('0.10') > import gst > > class Bufsrc(gst.BaseSrc): > """ Push text """ > #here we register our plugin details > __gstdetails__ = ( > "bufsrc test plugin", > "bufsrc.py", > "Source element that create a buffer", > "Oleksandr Lavrushchenko <[hidden email]>") > > _src_template = gst.PadTemplate ("src", > gst.PAD_SRC, > gst.PAD_ALWAYS, > gst.caps_new_any ()) > > __gsttemplates__ = (_src_template,) > > def __init__ (self, *args, **kwargs): > gst.BaseSrc.__init__(self) > gst.info('creating srcpad') > self.src_pad = gst.Pad (self._src_template) > self.src_pad.use_fixed_caps() > > #self.add_pad (self.src_pad) > > def do_create(self, offset, length): > buf = gst.Buffer("data\n") > buf.timestamp = 0 > buf.duration = pow(2, 63) -1 > return gst.FLOW_OK, buf > > # Register element class > gobject.type_register(Bufsrc) > gst.element_register(Bufsrc, 'bufsrc', gst.RANK_MARGINAL) > > sink = gst.element_factory_make("udpsink", "sink") > sink.set_property("port", 5000) > sink.set_property("host", "127.0.0.1") > > pusher = Bufsrc() > > player = gst.Pipeline("player") > player.add(pusher, sink) > gst.element_link_many(pusher2, sink) > > player.set_state(gst.STATE_PLAYING) > > gobject.MainLoop().run() > > > > _______________________________________________ > gstreamer-devel mailing list > [hidden email] > http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel > > gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi
On Sat, Jul 9, 2011 at 12:49 AM, Sandino Flores Moreno <[hidden email]> wrote: > > Just out of curiosity: > Why python and not C or Vala? First, this usually a question of taste. Second, i see next reasons for me: * it's easier to write, i love gst but usually it's C code for me a bit messy; * easier to debug; * less worries about memory management: pointers, memory allocation and freeing, etc.; * usually i want to prototype something and that's why i want see results as much as possible, in python code usually much shorter so faster to write. If, when code will be working, i see some performance issues, i will think about rewriting it from scratch in C. But at this point of time i, at minimum, will have clean understanding how it's must work, looking on python source. P.S. I'm not a programmer by education, so addressing all issues at one time (C issues, algorithm issues, etc) may become the way to fail. _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
First, thanks for the constructive comments.
I'm still busy writing my data source in python but the easiest way I have come across is to extend the videotestsource. Problem was that I cannot directly subclass it (not wrapped in python?) so I instantiated videotestsrc via gst.element_factory_make, got its type and extended this: xxx = gst.element_factory_make("videotestsrc", "video-source") xclass = type(xxx) Then, I can change the part where the data is actually created: class yyy(xclass): def do_create(self, offset, length): try: self._cnt; # i have no custom constructor, so I have to test if its here already except: self._cnt = 100; self.tic = time.time() # no, instantiate this here origOutStat, origOutBuf = xclass.do_create(self, offset, length) #parent output (videotestsrc) dat = scipy.zeros(len(origOutBuf),'uint8') # my dummy output for testing dat[:] = self._cnt # set to oscillating color, so we see something changing buf = gst.Buffer(dat.ravel()) # overwrite buffer self._cnt+=1 return gst.FLOW_OK, buf and register it: gobject.type_register(yyy) gst.element_register(yyy, 'yyy', gst.RANK_MARGINAL) This is rather ugly, but I think I can work my way on from here. Concerning the "why python" question: The comments in the posting above are all correct, additionally it depends of course on my infrastructure. The data source that generates my images happens to be in python, so it is the easiest way to stay within python. Thanks again, Mathias |
Free forum by Nabble | Edit this page |