aboutsummaryrefslogtreecommitdiff
path: root/voctocore/scripts/av-source-background-loop.py
blob: 9f4dc6d56cd70143d5c841f069697c23113e8972 (plain)
  1. #!/usr/bin/python3
  2. import sys, gi, signal
  3. gi.require_version('Gst', '1.0')
  4. from gi.repository import Gst, GObject
  5. # init GObject & Co. before importing local classes
  6. GObject.threads_init()
  7. Gst.init([])
  8. class LoopSource(object):
  9. def __init__(self):
  10. pipeline = """
  11. uridecodebin name=src uri=http://c3voc.mazdermind.de/bg.ts !
  12. video/x-raw,format=I420,width=1920,height=1080,framerate=25/1,pixel-aspect-ratio=1/1 !
  13. matroskamux !
  14. tcpclientsink host=localhost port=16000
  15. """
  16. self.senderPipeline = Gst.parse_launch(pipeline)
  17. self.src = self.senderPipeline.get_by_name('src')
  18. # Binding End-of-Stream-Signal on Source-Pipeline
  19. self.senderPipeline.bus.add_signal_watch()
  20. self.senderPipeline.bus.connect("message::eos", self.on_eos)
  21. self.senderPipeline.bus.connect("message::error", self.on_error)
  22. print("playing")
  23. self.senderPipeline.set_state(Gst.State.PLAYING)
  24. def on_eos(self, bus, message):
  25. print('Received EOS-Signal, Seeking to start')
  26. self.src.seek(
  27. 1.0, # rate (float)
  28. Gst.Format.TIME, # format (Gst.Format)
  29. Gst.SeekFlags.FLUSH, # flags (Gst.SeekFlags)
  30. Gst.SeekType.SET, # start_type (Gst.SeekType)
  31. 0, # start (int)
  32. Gst.SeekType.NONE, # stop_type (Gst.SeekType)
  33. 0 # stop (int)
  34. )
  35. def on_error(self, bus, message):
  36. print('Received Error-Signal')
  37. (error, debug) = message.parse_error()
  38. print('Error-Details: #%u: %s' % (error.code, debug))
  39. sys.exit(1)
  40. def main():
  41. signal.signal(signal.SIGINT, signal.SIG_DFL)
  42. src = LoopSource()
  43. mainloop = GObject.MainLoop()
  44. try:
  45. mainloop.run()
  46. except KeyboardInterrupt:
  47. print('Terminated via Ctrl-C')
  48. if __name__ == '__main__':
  49. main()