Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. VLC player inside QFrame on headless Linux
QtWS25 Last Chance

VLC player inside QFrame on headless Linux

Scheduled Pinned Locked Moved Unsolved Qt for Python
9 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zocker_160
    wrote on 12 May 2021, 17:02 last edited by
    #1

    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 online

    import 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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 May 2021, 18:30 last edited by
      #2

      Hi and welcome to devnet,

      There's the VLC-Qt project but I do not know if there's Python bindings for them.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zocker_160
        wrote on 14 May 2021, 13:30 last edited by
        #3

        ok so I guess it is currently not possible then unfortunately :/

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 May 2021, 18:42 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zocker_160
            wrote on 19 May 2021, 11:28 last edited by zocker_160
            #5

            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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 19 May 2021, 11:32 last edited by
              #6

              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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • Z Offline
                Z Offline
                zocker_160
                wrote on 19 May 2021, 20:15 last edited by zocker_160
                #7

                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 the setVideoWidget command, like it is used here.
                Sadly this does not seem to be implemented in Python.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 21 May 2021, 20:19 last edited by
                  #8

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    zocker_160
                    wrote on 21 May 2021, 23:02 last edited by zocker_160 6 Dec 2021, 23:34
                    #9

                    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.

                    1 Reply Last reply
                    0

                    7/9

                    19 May 2021, 20:15

                    • Login

                    • Login or register to search.
                    7 out of 9
                    • First post
                      7/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved