Exit Tkinter video from GStreamer?

Does anyone know how I will use the tkinter window as output from the video terminal / pipeline from within python? I found methods for many other GUI systems, but I do not want to use tkinter and something else together xxx thanks in advance x

+3
source share
1 answer

This works for me on 32bit Windows. I get a seg error on Linux or Windows 64-bit. Sorry, I don’t know about Mac.

You should use bus.connect ("sync-message :: element", on_sync_message) and pass the widget identifier Tk ( winfo_id ), as you can see in the following code. The container can be any Tk widget, but the solid black border seems to work best for me.

import sys, os
from Tkinter import *
import pygst
pygst.require("0.10")
import gst


def start():
        player.set_property('video-sink', None)
        player.set_property("uri", "file:///" + sys.argv[1])
        player.set_state(gst.STATE_PLAYING)

def on_sync_message(bus, message):
        if message.structure is None:
                return
        message_name = message.structure.get_name()
        if message_name == "prepare-xwindow-id":
                imagesink = message.src
                imagesink.set_property("force-aspect-ratio", True)
                imagesink.set_xwindow_id(mwin_id)

window = Tk()
window.geometry("500x400")
movie_window = Frame(window,bg='#000000')
movie_window.pack(side=BOTTOM,anchor=S,expand=YES,fill=BOTH)

mwin_id = movie_window.winfo_id()

player = gst.element_factory_make("playbin2", "player")
fakesink = gst.element_factory_make('fakesink', 'novideo')
player.set_property('video-sink', fakesink)

bus = player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("sync-message::element", on_sync_message)

start()
window.mainloop()
+2
source

Source: https://habr.com/ru/post/1790806/


All Articles