Skip to content Skip to sidebar Skip to footer

Set Vlc Window Dimensions In Vlc.py

I am using VLC in Python to open a video stream (UDP stream). How can I set the dimensions of the video window and its position on the screen This is the code import vlc i = vlc.I

Solution 1:

In short I don't think that you can, unless your provide it with a window to play in, that you control. This involves wrapping it within a gui, many people use Tkinter, wxPython or Qt for this. Below are samples written on Linux.

Here is a wxPython sample:

import vlc
import wx

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

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

    defstop(self,event):
        try:
            self.player.pause()
        except:
            pass
app = wx.App()
frame = MyFrame()
app.MainLoop()

This is a Tkinter version (forgive any quirks, I don't use Tkinter myself):

import tkinter as tk
import vlc

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

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

    defpause(self):
        try:
            self.player.pause()
        except:
            passif __name__ == '__main__':
    root = tk.Tk()
    root.title("Video Frame Tkinter")
    app = myframe(root)
    root.mainloop()

This is how they look on the screen: enter image description here

Post a Comment for "Set Vlc Window Dimensions In Vlc.py"