summaryrefslogtreecommitdiff
path: root/example-scripts/gstreamer/source-videotestsrc-as-cam1-with-networktime.py
blob: b07bf556e1697133c7ace6172c3aca0de0a402ee (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. clock = Gst.SystemClock.obtain()
  23. self.clock = GstNet.NetClientClock.new('voctocore', '127.0.0.1', 9998, clock.get_time())
  24. print('obtained NetClientClock from host', self.clock)
  25. self.senderPipeline = Gst.parse_launch(pipeline)
  26. self.senderPipeline.use_clock(self.clock)
  27. self.src = self.senderPipeline.get_by_name('src')
  28. # Binding End-of-Stream-Signal on Source-Pipeline
  29. self.senderPipeline.bus.add_signal_watch()
  30. self.senderPipeline.bus.connect("message::eos", self.on_eos)
  31. self.senderPipeline.bus.connect("message::error", self.on_error)
  32. print("playing")
  33. self.senderPipeline.set_state(Gst.State.PLAYING)
  34. def on_eos(self, bus, message):
  35. print('Received EOS-Signal')
  36. sys.exit(1)
  37. def on_error(self, bus, message):
  38. print('Received Error-Signal')
  39. (error, debug) = message.parse_error()
  40. print('Error-Details: #%u: %s' % (error.code, debug))
  41. sys.exit(1)
  42. def main():
  43. signal.signal(signal.SIGINT, signal.SIG_DFL)
  44. src = Source()
  45. mainloop = GObject.MainLoop()
  46. try:
  47. mainloop.run()
  48. except KeyboardInterrupt:
  49. print('Terminated via Ctrl-C')
  50. if __name__ == '__main__':
  51. main()