summaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py
blob: cf3870c3822a417503059196b823babbc029b796 (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=192,height=108,framerate=25/1,pixel-aspect-ratio=1/1 !\
  15. mux. \
  16. \
  17. audiotestsrc freq=330 !\
  18. audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000 !\
  19. mux. \
  20. \
  21. matroskamux name=mux !\
  22. tcpclientsink host=127.0.0.1 port=10000
  23. """
  24. clock = Gst.SystemClock.obtain()
  25. self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 9998, clock.get_time())
  26. print('obtained NetClientClock from host', self.clock)
  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()