Tkinter 中 GStreamer 的视频输出?

发布于 2024-10-16 15:07:49 字数 108 浏览 1 评论 0原文

有谁知道我将如何使用 tkinter 窗口作为 python 内的视频接收器/管道的输出?我已经找到了许多其他 GUI 系统的方法,但我不想必须同时使用 tkinter 和其他东西 xxx 预先感谢 x

does anyone know how i would go about using a tkinter window as an output from a videosink/pipeline from within python? i have found methods for lots of other GUI systems, but i dont want to have to use tkinter and something else together xxx
thanks in advance x

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小帐篷 2024-10-23 15:07:49

这对我在 Windows 32 位上有效。我在 Linux 或 Windows 64 位上遇到段错误。抱歉,我不知道Mac。

您必须使用 bus.connect("sync-message::element", on_sync_message) 并传递 Tk 小部件 ID (winfo_id),如下所示代码。容器可以是任何 Tk 小部件,但纯黑框架似乎最适合我。

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()

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

You have to use bus.connect("sync-message::element", on_sync_message) and pass a Tk widget ID (winfo_id), as you can see in the following code. The container can be any Tk widget, but a solid black frame 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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文