VLC player inside QFrame on headless Linux
-
I hope here is the right place to ask this question.
I am trying to play a video decoded by VLC inside a QWidget, here is my code I took from an example I found onlineimport sys import vlc from PyQt5 import QtCore, QtGui, QtWidgets class Player(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Player, self).__init__(parent) self.setWindowTitle("Media Player") # creating a basic vlc instance self.instance = vlc.Instance() self.mediaplayer = self.instance.media_player_new() ##########video frame self.videoframe = QtWidgets.QFrame( frameShape=QtWidgets.QFrame.Box, frameShadow=QtWidgets.QFrame.Raised ) self.mediaplayer.set_xwindow(self.videoframe.winId()) central_widget = QtWidgets.QWidget() self.setCentralWidget(central_widget) lay = QtWidgets.QVBoxLayout(central_widget) lay.addWidget(self.videoframe) filename = "/path/of/your/video.mp4" media = self.instance.media_new(filename) self.mediaplayer.set_media(media) self.mediaplayer.play() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) player = Player() player.show() player.resize(640, 480) sys.exit(app.exec_())
While this works great when running an X Server, I could not find a way to make this work on a headless Linux using the framebuffer.
The UI loads as it should, just there is no video playing and I think the issue is this:
self.mediaplayer.set_xwindow(self.videoframe.winId())
Any ideas how I can solve this?
Thank you in advance!
-
Hi and welcome to devnet,
There's the VLC-Qt project but I do not know if there's Python bindings for them.
-
ok so I guess it is currently not possible then unfortunately :/
-
Did you try to check VLC-Qt ?
When going headless there's the offscreen QPA backend but doing direct X11 coding will likely not allow to used it. It's worth a try though.
-
Yes I did check VLC-QT out and it might work. Sadly it would require me to rewrite my project in C++, because there don't seem to exist Python bindings for this.
-
From a quick search:
https://pypi.org/project/python-vlc/
And a Qt example for it:
https://github.com/oaubert/python-vlc/blob/master/examples/qtvlc.py
-
If you look into the sample you linked on line 161 you will find out, that it uses the same command as I do above, which I stated does not work. :(
EDIT:
when using VLC-QT with C++, I can set the video widget using thesetVideoWidget
command, like it is used here.
Sadly this does not seem to be implemented in Python. -
Sorry ! I mixed two different issues.
Sadly, the underlying code from VLC-Qt will have the same issue as it is also using set_xwindow.
So it looks at bit compromised from that point of view.
Out of curiosity, why do you need a video player on a headless system ?
-
So my goal is to create a dashboard type application, that offers multiple layouts (which are configurable from a webinterface) with placeholders, where the user can put either a video, an image or a webpage into. They will then get displayed on a screen.
By "headless" I mean a Linux system, that has no X server running, I want my application to be started directly from terminal while using the framebuffer for showing the UI. And so far also everything works, except for the videos.
The reason I want to use VLC, is because the QMediaplayer (which does technically work for my purpose btw.) has sadly major issues with RTSP and RTMP video streams. VLC on the other hand does work flawless.
The only solution I can think of right now is to use some very lite X server with e.g. Busybox as the DE to make this work.