aboutsummaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py
blob: 441a1293d78e364bf6a5a70148532a1e0fcee819 (plain)
  1. #!/usr/bin/python3
  2. import sys, gi, signal
  3. gi.require_version('Gst', '1.0')
  4. from gi.repository import Gst, GstNet, GObject
  5. # init GObject & Co. before importing local classes
  6. GObject.threads_init()
  7. Gst.init([])
  8. class Source(object):
  9. def __init__(self):
  10. # it works much better with a local file
  11. pipeline = """
  12. videotestsrc pattern=ball foreground-color=0x00ff0000 background-color=0x00440000 !
  13. timeoverlay !
  14. video/x-raw,format=I420,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 !
  15. mux.
  16. audiotestsrc freq=330 !
  17. audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000 !
  18. mux.
  19. matroskamux name=mux !
  20. tcpclientsink host=127.0.0.1 port=10000
  21. """
  22. self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 9998, 0)
  23. print('obtained NetClientClock from host', self.clock)
  24. print('waiting for NetClientClock to sync…')
  25. self.clock.wait_for_sync(Gst.CLOCK_TIME_NONE)
  26. print('starting pipeline')
  27. self.senderPipeline = Gst.parse_launch(pipeline)
  28. self.senderPipeline.use_clock(self.clock)
  29. self.src = self.senderPipeline.get_by_name('src')
  30. # Binding End-of-Stream-Signal on Source-Pipeline
  31. self.senderPipeline.bus.add_signal_watch()
  32. self.senderPipeline.bus.connect("message::eos", self.on_eos)
  33. self.senderPipeline.bus.connect("message::error", self.on_error)
  34. print("playing")
  35. self.senderPipeline.set_state(Gst.State.PLAYING)
  36. def on_eos(self, bus, message):
  37. print('Received EOS-Signal')
  38. sys.exit(1)
  39. def on_error(self, bus, message):
  40. print('Received Error-Signal')
  41. (error, debug) = message.parse_error()
  42. print('Error-Details: #%u: %s' % (error.code, debug))
  43. sys.exit(1)
  44. def main():
  45. signal.signal(signal.SIGINT, signal.SIG_DFL)
  46. src = Source()
  47. mainloop = GObject.MainLoop()
  48. try:
  49. mainloop.run()
  50. except KeyboardInterrupt:
  51. print('Terminated via Ctrl-C')
  52. if __name__ == '__main__':
  53. main()