summaryrefslogtreecommitdiff
path: root/voctocore/experiments/sync-videomix.py
blob: 0f6e7804bbc775967e06ff2e31ff790e3b5b4a98 (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. identity sync=true signal-handoffs=false !
  17. mix.
  18. videotestsrc pattern=green !
  19. {caps} !
  20. identity sync=true signal-handoffs=false !
  21. mix.
  22. videomixer name=mix !
  23. {caps} !
  24. identity name=sig !
  25. videoconvert !
  26. pngenc !
  27. multifilesink location=frame%04d.png
  28. """.format(
  29. caps='video/x-raw,height=450,width=800,format=I420,framerate=25/1'
  30. )
  31. self.pipeline = Gst.parse_launch(pipeline)
  32. sig = self.pipeline.get_by_name('sig')
  33. sig.connect('handoff', self.handoff)
  34. self.mix = self.pipeline.get_by_name('mix')
  35. self.state = 0
  36. def handoff(self, object, buffer):
  37. mixerpad = self.mix.get_static_pad('sink_1')
  38. print('handoff, alpha=%u' % self.state)
  39. mixerpad.set_property('alpha', self.state)
  40. self.state = 0 if self.state else 1
  41. def run(self):
  42. self.pipeline.set_state(Gst.State.PLAYING)
  43. self.mainloop.run()
  44. def kill(self):
  45. self.pipeline.set_state(Gst.State.NULL)
  46. self.mainloop.quit()
  47. example = Example()
  48. example.run()