无法使用Gtk.Overlay覆盖Gstreamer视频 [英] Cannot Overlay over Gstreamer Video with Gtk.Overlay

查看:126
本文介绍了无法使用Gtk.Overlay覆盖Gstreamer视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Python,PyGObject(Gtk 3)和GStreamer(0.11)的项目

I have a project with Python, PyGObject (Gtk 3), and GStreamer (0.11)

我的应用程序中有视频,因此我使用的是Gtk.Overlay小部件,因此可以在视频背景上放置其他视觉元素.(我需要这个,请相信我.)(由于小部件的数量以及这些小部件的特定位置和覆盖的需要,我使用的是Gtk.Fixed容器.)

I have video in my application, so I'm using a Gtk.Overlay widget so I can put other visual elements over the video background. (I need this, trust me.) (Due to the number of widgets, and the need for specific positioning and overlaying of these widgets, I'm using a Gtk.Fixed container.)

但是,在将Gtk.Overlay对象与通过"overlay.add_overlay(widget)"添加的内容一起使用时,该视频将不再可见.我仍然可以听到,但看不到.

However, in using the Gtk.Overlay object with anything added via "overlay.add_overlay(widget)", the video is no longer visible at all. I can still hear it, but I cannot see it.

下面的代码.

from gi.repository import Gtk, Gdk, GdkPixbuf, GdkX11
import pango
import pygst
pygst.require('0.10')
import gst
import Trailcrest
import os, sys
import cairo
from math import pi

class Video:

    def __init__(self):

        def on_message(bus, message): 
            if message.type == gst.MESSAGE_EOS: 
                # End of Stream 
                player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)
            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":
                Gdk.threads_enter()
                Gdk.Display.get_default().sync()
                win_id = videowidget.get_property('window').get_xid()
                imagesink = message.src
                imagesink.set_property("force-aspect-ratio", True)
                imagesink.set_xwindow_id(win_id)
                Gdk.threads_leave()

        def click_me(event, data=None):
            player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)

        win = Gtk.Window()
        win.set_resizable(False)
        win.set_decorated(False)
        win.set_position(Gtk.WindowPosition.CENTER)

        overlay = Gtk.Overlay()
        win.add(overlay)
        overlay.show()

        videowidget = Gtk.DrawingArea()
        overlay.add(videowidget)
        videowidget.set_halign (Gtk.Align.START)
        videowidget.set_valign (Gtk.Align.START)
        videowidget.set_size_request(640, 480)
        videowidget.show()

        fixed = Gtk.Fixed()
        overlay.add_overlay(fixed)
        fixed.show()

        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("IMG/IMG-MPG-LOGO.png", 250, 50)
        imgMPL = Gtk.Image()
        imgMPL.set_from_pixbuf(pixbuf)
        eb_imgMPL = Gtk.EventBox()
        eb_imgMPL.set_visible_window(False)
        eb_imgMPL.add(imgMPL)
        fixed.put(eb_imgMPL, 10, 10)
        imgMPL.show()
        eb_imgMPL.show()

        win.show_all()

        # 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/BGA-HABT-001.ogv")
        player.set_state(gst.STATE_PLAYING)


if __name__ == "__main__":
    Gdk.threads_enter()
    Video()
    Gtk.main()

如何解决这个小问题?

推荐答案

回答源自GNOME Bugzilla Bug 663589,注释1-3.

Answer derived from GNOME Bugzilla Bug 663589, Comments 1-3.

设置通过"add_overlay"添加的任何对象的valign和halign至关重要.

It is vital to set the valign and halign of any object added via "add_overlay".

因此,用于声明和添加Gtk.Fixed对象的修改后的代码如下.

Therefore, the revised code for declaring and adding the Gtk.Fixed object is as below.

fixed = Gtk.Fixed()

#The following two lines were added.
fixed.set_halign(Gtk.Align.START)
fixed.set_valign(Gtk.Align.START)

overlay.add_overlay(fixed)
fixed.show()

这篇关于无法使用Gtk.Overlay覆盖Gstreamer视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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