来自GStreamer的Tkinter视频输出?

时间:2011-02-08 20:21:16

标签: python tkinter gstreamer

有没有人知道如何使用tkinter窗口作为来自python内的videosink /管道的输出?我已经找到了许多其他GUI系统的方法,但我不想一起使用tkinter和其他东西xxx 提前谢谢x

1 个答案:

答案 0 :(得分:2)

这适用于Windows 32位。我在Linux或Windows 64位上遇到了seg故障。对不起,我不知道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()