Enigma2 plugin to to play various online streams (mostly Latvian).

test10.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import os, sys
  2. import Tkinter as tkinter
  3. import gi
  4. gi.require_version('Gst', '1.0')
  5. gi.require_version('GstVideo', '1.0')
  6. #gi.require_version('GdkX11', '3.0')
  7. from gi.repository import Gst, GObject, GstVideo
  8. def on_sync_message(bus, message, frame_id):
  9. if not message.get_structure() is None:
  10. print "sync: "+message.get_structure().get_name()
  11. if message.get_structure().get_name() == 'prepare-window-handle':
  12. display_frame = message.src
  13. display_frame.set_property('force-aspect-ratio', True)
  14. display_frame.set_window_handle(frame_id)
  15. def on_message(bus,message):
  16. t = message.type
  17. print "message: "+str(message.type)
  18. if t == Gst.MessageType.EOS:
  19. self.player.set_state(Gst.State.NULL)
  20. elif t == Gst.MessageType.ERROR:
  21. err, debug = message.parse_error()
  22. print "Error: %s" % err, debug
  23. self.player.set_state(Gst.State.NULL)
  24. window = tkinter.Tk()
  25. window.title('')
  26. window.geometry('500x400')
  27. GObject.threads_init()
  28. Gst.init(None)
  29. # can aslo use display_frame = tkinter.Frame(window)
  30. display_frame = tkinter.Canvas(window, bg='#030')
  31. display_frame.pack(side=tkinter.TOP,expand=tkinter.YES,fill=tkinter.BOTH)
  32. frame_id = display_frame.winfo_id()
  33. #player = Gst.ElementFactory.make('playbin', None)
  34. ##filepath = os.path.realpath('test.mp4')
  35. #filepath2 = "file:///" + filepath.replace('\\', '/').replace(':', '|')
  36. #player.set_property('uri', filepath2)
  37. cmd = 'souphttpsrc ssl-strict=false location="http://walterebert.com/playground/video/hls/ts/480x270.m3u8" ! decodebin! autovideosink'
  38. player = Gst.parse_launch(cmd)
  39. source = player.get_child_by_name('souphttpsrc0')
  40. pass
  41. #player = Gst.Pipeline("player")
  42. #source = Gst.ElementFactory.make("souphttpsrc", "source")
  43. #source.set_property("location","http://walterebert.com/playground/video/hls/ts/480x270.m3u8")
  44. #decodebin = Gst.ElementFactory.make("decodebin", "decodebin")
  45. #output = Gst.ElementFactory.make("autovideosink", "output")
  46. #player.add(source)
  47. #player.add(decodebin)
  48. #player.add(output)
  49. #source.link(decodebin)
  50. #decodebin.link(output)
  51. VideoCrop = Gst.ElementFactory.make('videocrop', 'VideoCrop')
  52. VideoCrop.set_property('top', 100)
  53. VideoCrop.set_property('bottom', 100)
  54. VideoCrop.set_property('left', 50)
  55. VideoCrop.set_property('right', 150)
  56. #player.set_property('video-filter', VideoCrop)
  57. bus = player.get_bus()
  58. bus.add_signal_watch()
  59. bus.enable_sync_message_emission()
  60. bus.connect("message", on_message)
  61. bus.connect('sync-message::element', on_sync_message, frame_id)
  62. player.set_state(Gst.State.PLAYING)
  63. window.mainloop()