视频(GStreamer)出现奇异的间歇性错误 [英] Bizarre Intermittent Error on Video (GStreamer)

查看:243
本文介绍了视频(GStreamer)出现奇异的间歇性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project that runs Python 2.7, PyGTK 2.24, and the most recent version of PyGST.

我在以下代码中遇到一个奇怪的间歇性错误.如果出现第一个较长的错误,则视频将正常播放,并且该错误仅在关闭视频窗口后才会出现.第二个阻止窗口完全打开.

I am getting a weird intermittent error in the following code. With the first, longer error, the video will play just fine, and the error will only appear AFTER I close the video window. The second prevents the window from opening at all.

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

程序"Video.py"收到X Window系统错误.这 可能反映了程序中的错误.错误是"BadIDChoice (为此连接选择了无效的资源ID)". (详细信息:串行 373错误代码14请求代码1次代码0)(程序员注意: 通常,X错误是异步报告的;也就是说,你会 造成错误后一段时间内收到错误.要调试程序, 使用--sync命令行选项运行它以更改此行为. 然后,您可以从调试器中获取有意义的回溯信息,如果您 中断gdk_x_error()函数.)

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上),我再次收到了该消息.

A quick note on this...I followed the instructions and ran "python Video.py --sync" in command line (I'm on Kubuntu), and I got that message AGAIN.

这是另一个错误-一个根本无法播放的错误.

Here's the other error - the one that prevents playback at all.

python:../../src/xcb_io.c:221:poll_for_event:断言`((((long) (event_sequence)-(long)(dpy-> request))< = 0)'失败.中止

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

尽管不是十全十美,但它们实际上会交替出现.我可以得到三个中的三个,第二个中的两个,一个第一,一个第二,两个第一,依此类推.它总是不同的.

These will literally alternate, though not perfectly. I could get three of the first, two of the second, one first, one second, two first, etc. It is always different.

魔鬼在这里发生什么事?

What the devil is going on here?

推荐答案

您需要与X服务器同步以获得窗口xid.

You need to synchronise with X server to get window 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()

这篇关于视频(GStreamer)出现奇异的间歇性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆