Advertisement
tripzero

GstVideoFilter

Feb 8th, 2015
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import gi
  4. gi.require_version('Gst', '1.0')
  5. from gi.repository import Gst, GObject, Gtk, GstVideo
  6.  
  7. GObject.threads_init()
  8. Gst.init(None)
  9.  
  10. class NewElement(GstVideo.VideoFilter):
  11.  
  12. __gstmetadata__ = (
  13. "NewElement plugin",
  14. "newelement",
  15. "Description",
  16. "Contact")
  17.  
  18. _srctemplate = Gst.PadTemplate.new('src',
  19. Gst.PadDirection.SRC,
  20. Gst.PadPresence.ALWAYS,
  21. Gst.Caps.from_string("video/x-raw,format=RGB, depth=8, width=640, height=480"))
  22.  
  23. _sinktemplate = Gst.PadTemplate.new('sink',
  24. Gst.PadDirection.SINK,
  25. Gst.PadPresence.ALWAYS,
  26. Gst.Caps.from_string("video/x-raw,format=RGB, depth=8, width=640, height=480"))
  27.  
  28. __gsttemplates__ = (_srctemplate, _sinktemplate)
  29.  
  30. def __init__(self):
  31. GstVideo.VideoFilter.__init__(self)
  32. self.set_passthrough(True)
  33.  
  34. def do_transform_frame(self, inframe, outframe):
  35. print "do transform!"
  36. return Gst.FlowReturn.OK
  37.  
  38. def do_transform_frame_ip(self, frame):
  39. print "do transform ip!"
  40. return Gst.FlowReturn.OK
  41.  
  42. def do_set_info(self, incaps, in_info, outcaps, out_info):
  43. print "incaps:", incaps.to_string()
  44. return True
  45.  
  46. def plugin_init(plugin):
  47. print "registering plugin"
  48. t = GObject.type_register (NewElement)
  49. Gst.Element.register(plugin, "newelement", 0, t)
  50. return True
  51.  
  52. if not Gst.Plugin.register_static(Gst.VERSION_MAJOR, Gst.VERSION_MINOR, "newelement", "newelement filter plugin", plugin_init, '12.06', 'LGPL', 'newelement', 'newelement', ''):
  53. print "plugin register failed"
  54. sys.exit()
  55.  
  56. source = Gst.ElementFactory.make("videotestsrc")
  57. print "making new element"
  58. newElement = Gst.ElementFactory.make("newelement")
  59. print "made new element"
  60. vsink = Gst.ElementFactory.make("autovideosink")
  61. # create the pipeline
  62.  
  63. p = Gst.Pipeline()
  64. p.add(source)
  65. p.add(newElement)
  66. p.add(vsink)
  67.  
  68. source.link(newElement)
  69. newElement.link(vsink)
  70. # set pipeline to playback state
  71.  
  72. print "playing"
  73. p.set_state(Gst.State.PLAYING)
  74.  
  75. import signal
  76. signal.signal(signal.SIGINT, signal.SIG_DFL)
  77.  
  78. Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement