summaryrefslogtreecommitdiff
path: root/voctocore/experiments/sync-videomix.py
blob: 1e17a2e60c2535529fa689b67ab78aa45a7754f6 (plain)
  1. #!/usr/bin/python3
  2. import gi, time
  3. import socket
  4. # import GStreamer and GTK-Helper classes
  5. gi.require_version('Gst', '1.0')
  6. from gi.repository import GLib, Gst, GObject
  7. # init GObject before importing local classes
  8. GObject.threads_init()
  9. Gst.init(None)
  10. class Example:
  11. def __init__(self):
  12. self.mainloop = GObject.MainLoop()
  13. pipeline = """
  14. videotestsrc pattern=red !
  15. {caps} !
  16. videoscale !
  17. capsfilter name=caps0 !
  18. identity sync=true signal-handoffs=false !
  19. mix.
  20. videotestsrc pattern=green !
  21. {caps} !
  22. videoscale !
  23. capsfilter name=caps1 !
  24. identity sync=true signal-handoffs=false !
  25. mix.
  26. videomixer name=mix !
  27. {caps} !
  28. identity name=sig !
  29. videoconvert !
  30. pngenc !
  31. multifilesink location=frame%04d.png
  32. """.format(
  33. caps='video/x-raw,width=800,height=450,format=I420,framerate=25/1'
  34. )
  35. self.pipeline = Gst.parse_launch(pipeline)
  36. sig = self.pipeline.get_by_name('sig')
  37. sig.connect('handoff', self.handoff)
  38. self.pad0 = self.pipeline.get_by_name('mix').get_static_pad('sink_0')
  39. self.pad1 = self.pipeline.get_by_name('mix').get_static_pad('sink_1')
  40. self.caps0 = self.pipeline.get_by_name('caps0')
  41. self.caps1 = self.pipeline.get_by_name('caps1')
  42. self.state = False
  43. def handoff(self, object, buffer):
  44. if self.state:
  45. padA = self.pad0
  46. padB = self.pad1
  47. capsA = self.caps0
  48. capsB = self.caps1
  49. else:
  50. padA = self.pad1
  51. padB = self.pad0
  52. capsA = self.caps1
  53. capsB = self.caps0
  54. padA.set_property('xpos', 10)
  55. padA.set_property('ypos', 10)
  56. padA.set_property('alpha', 1.0)
  57. padA.set_property('zorder', 1)
  58. capsA.set_property('caps', Gst.Caps.from_string('video/x-raw,width=400,height=225'))
  59. padB.set_property('xpos', 390)
  60. padB.set_property('ypos', 215)
  61. padB.set_property('alpha', 1.0)
  62. padB.set_property('zorder', 2)
  63. capsB.set_property('caps', Gst.Caps.from_string('video/x-raw,width=400,height=225'))
  64. self.state = not self.state
  65. def run(self):
  66. self.pipeline.set_state(Gst.State.PLAYING)
  67. self.mainloop.run()
  68. def kill(self):
  69. self.pipeline.set_state(Gst.State.NULL)
  70. self.mainloop.quit()
  71. example = Example()
  72. example.run()