gpt4 book ai didi

python - 奇怪的视频间歇性错误 (GStreamer)

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:59 25 4
gpt4 key购买 nike

我有一个运行 Python 2.7、PyGTK 2.24 和最新版本 PyGST 的项目。

我在以下代码中遇到奇怪的间歇性错误。对于第一个较长的错误,视频可以正常播放,并且只有在我关闭视频窗口后才会出现错误。第二个阻止窗口打开。

import pygtk
pygtk.require('2.0')
import gtk, pango
import pygst
pygst.require('0.10')
import gst
import Trailcrest
import os, sys

class Video:

def __init__(self):

def on_message(bus, message):
if message.type == gst.MESSAGE_EOS:
# End of Stream
player.set_state(gst.STATE_NULL)
elif message.type == gst.MESSAGE_ERROR:
player.set_state(gst.STATE_NULL)
(err, debug) = message.parse_error()
print "Error: %s" % err, debug

def on_sync_message(bus, message):
if message.structure is None:
return False
if message.structure.get_name() == "prepare-xwindow-id":
if sys.platform == "win32":
win_id = videowidget.window.handle
else:
win_id = videowidget.window.xid
assert win_id
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)

win = gtk.Window()
win.set_resizable(False)
win.set_has_frame(False)
win.set_position(gtk.WIN_POS_CENTER)

fixed = gtk.Fixed()
win.add(fixed)
fixed.show()

videowidget = gtk.DrawingArea()
fixed.put(videowidget, 0, 0)
videowidget.set_size_request(640, 480)
videowidget.show()

# Setup GStreamer
player = gst.element_factory_make("playbin", "MultimediaPlayer")
bus = player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
#used to get messages that GStreamer emits
bus.connect("message", on_message)
#used for connecting video to your application
bus.connect("sync-message::element", on_sync_message)
player.set_property("uri", "file://" + os.getcwd() + "/VID/SEQ-GAME-OPEN.ogv")
player.set_state(gst.STATE_PLAYING)

win.show()

def main():
gtk.gdk.threads_init()
gtk.main()
return 0

if __name__ == "__main__":
Video()
main()

The program 'Video.py' received an X Window System error. This probably reflects a bug in the program. The error was 'BadIDChoice (invalid resource ID chosen for this connection)'. (Details: serial 373 error_code 14 request_code 1 minor_code 0) (Note to programmers: normally, X errors are reported asynchronously; that is, you will receive the error a while after causing it. To debug your program, run it with the --sync command line option to change this behavior. You can then get a meaningful backtrace from your debugger if you break on the gdk_x_error() function.)

关于此的快速说明...我按照说明在命令行中运行“python Video.py --sync”(我在 Kubuntu 上),我再次收到该消息。

这是另一个错误 - 完全阻止播放的错误。

python: ../../src/xcb_io.c:221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy->request)) <= 0)' failed. Aborted

这些将逐字交替,但并不完美。我可以获得三个第一,两个第二,一个第一,一个第二,两个第一,等等。它总是不同的。

这到底是怎么回事?

最佳答案

需要与X server同步获取窗口xid。

方法如下:

    def on_sync_message(bus, message):
if message.structure is None:
return False
if message.structure.get_name() == "prepare-xwindow-id":
gtk.gdk.threads_enter()
gtk.gdk.display_get_default().sync()
win_id = videowidget.window.xid
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)
gtk.gdk.threads_leave()

关于python - 奇怪的视频间歇性错误 (GStreamer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7369712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com