在python中使用Gstreamer'playbin','set_window_handle'代码告诉Gstreamer用于呈现视频的窗口ID:
这适用于标准Linux Mate以及运行Ubuntu-Mate的Raspberry Pi 3。但是,在同一个Raspberry上运行但运行最新的Raspbian操作系统,Gstreamer完全忽略了在特定窗口中运行的指令,而是创建了自己的窗口,在屏幕中间闪烁。
如果新窗口能够被操纵,移动和/或调整大小但它不能,则这不是问题。它无法移动,无法关闭,鼠标指针在其后面消失
有没有人知道这是Raspbian,X windows或Gstreamer中的错误还是我没有发现为了在Raspbian OS上工作必须实施的一些更改?
这是一个最小的工作示例,它说明了上述行为。
#!/usr/bin/env python
import os,time
import wx
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst
from gi.repository import GstVideo
class Player(wx.App):
def OnInit(self):
window = wx.Frame(None)
window.SetTitle("Gstreamer Player Test")
window.SetSize((-1,-1))
window.Bind(wx.EVT_CLOSE,self.close)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.fileid = wx.TextCtrl(window,style=wx.TE_PROCESS_ENTER)
self.fileid.SetToolTipString("Enter full path to media file")
hbox.Add(self.fileid, 1)
self.start = wx.Button(window,label="Start")
hbox.Add(self.start, 0)
self.start.Bind(wx.EVT_BUTTON, self.control)
self.fileid.Bind(wx.EVT_TEXT_ENTER, self.control)
vbox.Add(hbox, 0, wx.EXPAND, 0)
self.video_window = wx.Panel(window)
vbox.Add(self.video_window,1,wx.EXPAND,5)
window.SetSizer(vbox)
window.Layout()
window.Show()
self.SetTopWindow(window)
Gst.init(None) #initialise gstreamer
self.player = Gst.ElementFactory.make("playbin", "player")
bus = self.player.get_bus()
bus.add_signal_watch() #hook up bus to signals from gstreamer
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
bus.connect('sync-message::element', self.on_sync_message)
return True
def control(self, event):
if self.start.GetLabel() == "Start":
fileid = self.fileid.GetValue()
if os.path.exists(fileid):
self.start.SetLabel("Stop")
fileid = "file://"+unicode(fileid)
self.player.set_property('uri', fileid)
self.player.set_state(Gst.State.PLAYING)
else:
print "File error - No such file"
else:
self.player.set_state(Gst.State.NULL)
self.start.SetLabel("Start")
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.EOS: # media has ended
self.player.set_state(Gst.State.NULL)
self.button.SetLabel("Start")
elif t == Gst.MessageType.ERROR:
print "Player error"
self.player.set_state(Gst.State.NULL)
self.start.SetLabel("Start")
def on_sync_message(self, bus, message):
if message.get_structure() is None:
return True
message_name = message.get_structure().get_name()
if message_name == 'prepare-window-handle': #Assign the window id to display in
imagesink = message.src
imagesink.set_property('force-aspect-ratio', True) #Force size to fit window
X_id = self.video_window.GetHandle()
print ("Window Id:", X_id)
imagesink.set_window_handle(X_id)
return True
def close(self,event):
self.player.set_state(Gst.State.NULL)
time.sleep(0.1) #Allow a little time to reach Null state
event.Skip()
app = Player()
app.MainLoop()
答案 0 :(得分:0)
答案是这是一个错误 Bugzilla link
无论是在gstreamer还是Rpi堆栈中,似乎都没有实际意义 解决方法是在playbin管道中指定videosink 所以对于这个特定的程序应该如下:
#!/usr/bin/env python
import os,time
import wx
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst
from gi.repository import GstVideo
class Player(wx.App):
def OnInit(self):
window = wx.Frame(None)
window.SetTitle("Gstreamer Player Test")
window.SetSize((-1,-1))
window.Bind(wx.EVT_CLOSE,self.close)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.fileid = wx.TextCtrl(window,style=wx.TE_PROCESS_ENTER)
self.fileid.SetToolTipString("Enter full path to media file")
hbox.Add(self.fileid, 1)
self.start = wx.Button(window,label="Start")
hbox.Add(self.start, 0)
self.start.Bind(wx.EVT_BUTTON, self.control)
self.fileid.Bind(wx.EVT_TEXT_ENTER, self.control)
vbox.Add(hbox, 0, wx.EXPAND, 0)
video_window = wx.Panel(window)
vbox.Add(video_window,1,wx.EXPAND,5)
window.SetSizer(vbox)
window.Layout()
window.Show()
self.SetTopWindow(window)
Gst.init(None) #initialise gstreamer
self.X_id = video_window.GetHandle()
self.player = Gst.ElementFactory.make("playbin", "player")
# self.ximagesink = Gst.ElementFactory.make("xvimagesink", None)
self.ximagesink = Gst.ElementFactory.make("ximagesink", None)
self.player.set_property('video-sink', self.ximagesink)
bus = self.player.get_bus()
bus.add_signal_watch() #hook up bus to signals from gstreamer
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
bus.connect('sync-message::element', self.on_sync_message)
return True
def control(self, event):
if self.start.GetLabel() == "Start":
fileid = self.fileid.GetValue()
if os.path.exists(fileid):
self.start.SetLabel("Stop")
fileid = "file://"+unicode(fileid)
self.player.set_property('uri', fileid)
self.player.set_state(Gst.State.PLAYING)
else:
print "File error - No such file"
else:
self.player.set_state(Gst.State.NULL)
self.start.SetLabel("Start")
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.EOS: # media has ended
self.player.set_state(Gst.State.NULL)
self.button.SetLabel("Start")
elif t == Gst.MessageType.ERROR:
print "Player error"
self.player.set_state(Gst.State.NULL)
self.start.SetLabel("Start")
def on_sync_message(self, bus, message):
if message.get_structure() is None:
return True
message_name = message.get_structure().get_name()
if message_name == 'prepare-window-handle': #Assign the window id to display in
imagesink = message.src
# imagesink.set_property('force-aspect-ratio', True) #Defaults anyway
imagesink.set_window_handle(self.X_id)
return True
def close(self,event):
self.player.set_state(Gst.State.NULL)
time.sleep(0.1) #Allow a little time to reach Null state
event.Skip()
app = Player()
app.MainLoop()
但是,如果您在LibreOffice宏中使用“com.sun.star.comp.avmedia.Manager_GStreamer”时遇到同样的问题,那么这对您没有任何好处,因为Libreoffice开发人员做出了与我相同的假设。似乎无法从Libreoffice中定义视频链接。在这种情况下,我们只需要等到错误修复进入一般版本。
注意:使用ximagesink
使用xvimagesink
会在Raspbian上出错,因为Xv软件存在无法使用适配器的问题
使用glimagesink
为我们提供了卡在屏幕中间的可怕窗口,似乎eglesssink
已经悄然退出服务,因为它不再包含在Raspberry上的gstreamer插件中。