从GStreamer在Tkinter中的视频输出?

有谁知道我将如何使用tkinter窗口作为python内部videoink / pipeline的输出?我已经找到了许多其他GUI系统的方法,但我不想必须同时使用tkinter和其他功能xxx
预先感谢x

解决方法:

这对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()
上一篇:python-gstreamer appsrc适用于xvimagesink,但在theoraenc中却没有! oggmux


下一篇:在Java上的rtsp流