0

I tried litarely every code I found on the internet to start a python-vlc player instance in a window frame made with PyQt but it's no working. The vlc player starts in a new window instead of taking the one provided py PyQt.

Can someone reproduce my problem or even solve it? I'm on Ubuntu 22.04.4 LTS using Gnome and Wayland.

Minimal example:

import sys
import vlc
from PyQt6.QtWidgets import QMainWindow, QWidget, QApplication, QVBoxLayout, QFrame
from PyQt6.QtCore import Qt

class MediaPlayer(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("Media Player")
        self.initUI()

    def initUI(self):
        self.instance = vlc.Instance("--no-xlib")
        self.media = "path/to/video"  # Replace with your actual video file path
        self.mediaplayer = self.instance.media_player_new(self.media)
        self.mediaplayer.play()

        self.centralWidget = QWidget(self)
        self.setCentralWidget(self.centralWidget)

        layout = QVBoxLayout(self.centralWidget)
        self.videoFrame = QFrame()
        layout.addWidget(self.videoFrame)

        self.mediaplayer.set_xwindow(int(self.videoFrame.winId()))
        self.resize(640, 480)

def main():
    app = QApplication(sys.argv)
    player = MediaPlayer()
    player.show()
    sys.exit(app.exec())

if __name__ == "__main__":
    main()

Producing this error:

[00007c72c40b27a0] xcb_window window error: bad X11 window 0x00000003
[00007c72c40d2530] vdpau_avcodec generic error: Xlib is required for VDPAU
[00007c72c40b27a0] xcb_window window error: X server failure

I tried the also the following examples, non of them is working for me:

7
  • I'd start by setting the win id before beginning playback. Also note that the error declares that in order to use VDPAU (GPU acceleration) you must use Xlib, otherwise you have to disable acceleration. Commented Jun 30 at 17:06
  • Setting the win id before beginning the playback doesn't make a difference. If I use Xlib I get the following error: egl_x11 gl error: Xlib not initialized for threads, xcb_window window error: X server failure Commented Jun 30 at 19:40
  • Works fine for me on arch linux with the openbox window-manager. I also get the vdpau_avcodec error, but it does not prevent video display. I would suggest moving all the vlc/mediaplayer stuff to a separate method, and then use a single-shot timer to call it after a short delay.
    – ekhumoro
    Commented Jun 30 at 19:42
  • @timtombobjohn In any case, you should not start playback before setting the video output. Also, if you're using Wayland, this may not be possible yet (see this report). Commented Jul 1 at 11:47
  • @ekhumoro thanks for the recommendation, but still does the same thing. First opens the QFrame window, then the vlc player seperatly. Commented Jul 1 at 18:32

0

Browse other questions tagged or ask your own question.