1

我尝试在 playbin 视频上覆盖具有透明背景的十字准线,但无法显示视频。我发现了一些类似的问题,但答案不起作用(自发布以来可能发生了一些变化。我尝试了这些答案中的原始代码,但它们似乎不起作用)。根据https://bugzilla.gnome.org/show_bug.cgi?id=663589,我设置了对齐方式,但该应用程序只显示覆盖的图像而不是视频。

#!/usr/bin/env python3
import sys
# gtk libs (GUI).
import gi
gi.require_version("Gtk", "3.0")
gi.require_version('GstVideo', '1.0')
gi.require_version('Gst', '1.0')

from gi.repository import Gtk
from gi.repository import Gst
from gi.repository import GstVideo
from gi.repository import GdkPixbuf

def on_realize(widget, player):
    print(f'on_realize - check playbin: {player.get_name()}')

    window = widget.get_window()
    window_handle = window.get_xid()

    # pass it to playbin, which implements XOverlay and will forward
    # it to the video sink
    player.set_window_handle(window_handle)


class Video:

    def __init__(self):
        # initialize GTK and GStreamer
        Gtk.init(sys.argv)
        Gst.init(sys.argv)

        # Setup GStreamer 
        player = Gst.ElementFactory.make("playbin", "testplaybin")
        player.set_property("uri", "https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm")

        win = Gtk.Window()
        win.set_position(Gtk.WindowPosition.CENTER)

        # Add overlay box.
        overlay = Gtk.Overlay()
        win.add(overlay)
        overlay.set_size_request(700, 500)

        # Add drawing area to overlay box.
        videowidget = Gtk.DrawingArea()
        videowidget.connect("realize", on_realize, player)
        overlay.add(videowidget)
        #videowidget.set_halign (Gtk.Align.END)
        #videowidget.set_valign (Gtk.Align.END)

        # png image with a cross at the center and transparent background.
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("crosshair.png", 700, 500)
        img = Gtk.Image()
        img.set_from_pixbuf(pixbuf)
        overlay.add_overlay(img)
        # Set alignment per https://bugzilla.gnome.org/show_bug.cgi?id=663589
        img.set_halign (Gtk.Align.END)
        img.set_valign (Gtk.Align.END)

        print("playing video clip ...")
        player.set_state(Gst.State.PLAYING)
        win.show_all()


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

0 回答 0