我正在Python中使用VLC打开视频流(UDP流)。 如何设置视频窗口的尺寸及其在屏幕上的位置
这是代码
import vlc
i = vlc.Instance()
p = i.media_player_new()
p.set_mrl('udp://@224.1.1.1:1234')
p.play()
答案 0 :(得分:0)
简而言之,除非您提供window
供您玩,否则我认为您无法控制。
这涉及将其包装在gui
中,许多人为此使用Tkinter
,wxPython
或Qt
。以下是在Linux上编写的示例。
这是一个wxPython示例:
import vlc
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Video Frame WxPython", size=(500,400))
self.panel = wx.Panel(self, id= -1, pos=(10,10), size=(470,300))
self.play_button = wx.Button(self, -1, "Play", pos=(10,320))
self.stop_button = wx.Button(self, -1, "Pause", pos=(100,320))
self.Bind(wx.EVT_BUTTON, self.play, self.play_button)
self.Bind(wx.EVT_BUTTON, self.stop, self.stop_button)
self.panel.SetBackgroundColour(wx.BLACK)
self.Show()
def play(self,event):
vlc_options = '--no-xlib --quiet'
inst = vlc.Instance(vlc_options)
self.player = inst.media_player_new()
self.player.set_mrl('file:///home/rolf/BBB.ogv')
xid = self.panel.GetHandle()
self.player.set_xwindow(xid)
self.player.play()
def stop(self,event):
try:
self.player.pause()
except:
pass
app = wx.App()
frame = MyFrame()
app.MainLoop()
这是Tkinter版本(请原谅任何怪癖,我自己都不使用Tkinter):
import tkinter as tk
import vlc
class myframe(tk.Frame):
def __init__(self, root, width=500, height=400, bd=5):
super(myframe, self).__init__(root)
self.grid()
self.frame = tk.Frame(self, width=450, height=350, bd=5)
self.frame.configure(bg="black")
self.frame.grid(row=0, column=0, columnspan=2, padx=8)
self.play_button = tk.Button(self, text = 'Play', command = self.play)
self.play_button.grid(row=1, column=0, columnspan=1, padx=8)
self.stop_button = tk.Button(self, text = 'Pause', command = self.pause)
self.stop_button.grid(row=1, column=1, columnspan=1, padx=8)
def play(self):
i = vlc.Instance('--no-xlib --quiet')
self.player = i.media_player_new()
self.player.set_mrl('file:///home/rolf/BBB.ogv')
xid = self.frame.winfo_id()
self.player.set_xwindow(xid)
self.player.play()
def pause(self):
try:
self.player.pause()
except:
pass
if __name__ == '__main__':
root = tk.Tk()
root.title("Video Frame Tkinter")
app = myframe(root)
root.mainloop()