';非类型';对象没有属性';设置#u属性';Tkinter,GStreamer蟒蛇3

';非类型';对象没有属性';设置#u属性';Tkinter,GStreamer蟒蛇3,tkinter,gstreamer,Tkinter,Gstreamer,我正在尝试用tkinter、GStreamer和python3制作一个视频播放器,我有以下代码 import sys, os from tkinter import * from gi.repository import GObject from gi.repository import GLib from gi.repository import Gtk from gi.repository import Gst def start(): player.set_property

我正在尝试用tkinter、GStreamer和python3制作一个视频播放器,我有以下代码

import sys, os
from tkinter import *
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gst
def start():
        player.set_property('video-sink', None)
        player.set_property("uri", "./video.avi")
        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.ElementFactory.make("playbin2", "player")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
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)


window.mainloop()
start()
但我收到一个错误:

(reproductor4.py:6856): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed
Traceback (most recent call last):
  File "reproductor4.py", line 30, in <module>
    player.set_property("video-sink", fakesink)
AttributeError: 'NoneType' object has no attribute 'set_property'
(reproductor4.py:6856):GStreamer-CRITICAL**:gst\u-element\u-factory\u-make:断言“gst\u已初始化()”失败
回溯(最近一次呼叫最后一次):
文件“reproductor4.py”,第30行,在
player.set_属性(“视频接收器”,fakesink)
AttributeError:“非类型”对象没有属性“set\u属性”

关于为什么会发生这种情况的一些想法?

第30行是
播放器。设置\u属性(“视频接收器”,fakesink)
。回溯和属性错误消息似乎声称
player
为无。在该行之前使用
print(player)
进行测试。但是,在
回溯之前,我不理解额外的消息。这表明gst代码中的断言失败。

您的问题实际上是:

(reproductor4.py:6856): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized ()' failed

代码中没有调用初始化例程:gst_init()(在python中可能是gst.init())。没有初始化,gstreamer将无法工作。

解决方案如下: 最后,在调用之前仅附加以下行: GObject.threads_init()
Gst.init(None)

非常感谢您最后我不得不初始化对象,并且只有append:GObject.threads\u init()Gst.init(None)