import os, sys import Tkinter as tkinter import gi gi.require_version('Gst', '1.0') gi.require_version('GstVideo', '1.0') #gi.require_version('GdkX11', '3.0') from gi.repository import Gst, GObject, GstVideo def on_sync_message(bus, message, frame_id): if not message.get_structure() is None: print "sync: "+message.get_structure().get_name() if message.get_structure().get_name() == 'prepare-window-handle': display_frame = message.src display_frame.set_property('force-aspect-ratio', True) display_frame.set_window_handle(frame_id) def on_message(bus,message): t = message.type print "message: "+str(message.type) if t == Gst.MessageType.EOS: self.player.set_state(Gst.State.NULL) elif t == Gst.MessageType.ERROR: err, debug = message.parse_error() print "Error: %s" % err, debug self.player.set_state(Gst.State.NULL) window = tkinter.Tk() window.title('') window.geometry('500x400') GObject.threads_init() Gst.init(None) # can aslo use display_frame = tkinter.Frame(window) display_frame = tkinter.Canvas(window, bg='#030') display_frame.pack(side=tkinter.TOP,expand=tkinter.YES,fill=tkinter.BOTH) frame_id = display_frame.winfo_id() #player = Gst.ElementFactory.make('playbin', None) ##filepath = os.path.realpath('test.mp4') #filepath2 = "file:///" + filepath.replace('\\', '/').replace(':', '|') #player.set_property('uri', filepath2) cmd = 'souphttpsrc ssl-strict=false location="http://walterebert.com/playground/video/hls/ts/480x270.m3u8" ! decodebin! autovideosink' player = Gst.parse_launch(cmd) source = player.get_child_by_name('souphttpsrc0') pass #player = Gst.Pipeline("player") #source = Gst.ElementFactory.make("souphttpsrc", "source") #source.set_property("location","http://walterebert.com/playground/video/hls/ts/480x270.m3u8") #decodebin = Gst.ElementFactory.make("decodebin", "decodebin") #output = Gst.ElementFactory.make("autovideosink", "output") #player.add(source) #player.add(decodebin) #player.add(output) #source.link(decodebin) #decodebin.link(output) VideoCrop = Gst.ElementFactory.make('videocrop', 'VideoCrop') VideoCrop.set_property('top', 100) VideoCrop.set_property('bottom', 100) VideoCrop.set_property('left', 50) VideoCrop.set_property('right', 150) #player.set_property('video-filter', VideoCrop) bus = player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() bus.connect("message", on_message) bus.connect('sync-message::element', on_sync_message, frame_id) player.set_state(Gst.State.PLAYING) window.mainloop()