Tuesday 22 September 2020

Running video in Python using VLC and PyQt doesn't start

I'm trying to get a video to play in a frame in PyQt through VLC, I followed a similar question on here to get the sample code to use:

class VideoPlayer(QMainWindow):
    def __init__(self, parent, inputPath):
        super(VideoPlayer, 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 = QFrame(
            frameShape=QFrame.Box, frameShadow=QFrame.Raised
        )

        if sys.platform.startswith("linux"):  # for Linux using the X Server
            self.mediaplayer.set_xwindow(self.videoframe.winId())
        elif sys.platform == "win32":  # for Windows
            self.mediaplayer.set_hwnd(self.videoframe.winId())
        elif sys.platform == "darwin":  # for MacOS
            self.mediaplayer.set_nsobject(self.videoframe.winId())

        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        lay = QVBoxLayout(central_widget)
        lay.addWidget(self.videoframe)

        filename = inputPath
        media = self.instance.media_new(filename)
        self.mediaplayer.set_media(media)
        self.mediaplayer.play()

Trying to run this just gives me these errors whenever I start it up though:

[0c92dc18] mmdevice audio output error: cannot initialize COM (error 0x80010106)
[0ef89108] mmdevice audio output error: cannot initialize COM (error 0x80010106)
[0f07f308] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
[0f07f308] direct3d9 vout display error: SetThumbNailClip failed: 0x800706f4
[0f07f308] glwin32 vout display error: Win32VoutCreateWindow RegisterClass FAILED (err=1410)
[0f07f308] glwin32 vout display error: SetThumbNailClip failed: 0x800706f4
[0efbc4b8] wgl gl error: Could not get the device context
[0f07f308] directdraw vout display error: Win32VoutCreateWindow RegisterClass FAILED (err=1410)
[0f07f308] directdraw vout display error: SetThumbNailClip failed: 0x800706f4
[0f07f308] wingdi vout display error: Win32VoutCreateWindow RegisterClass FAILED (err=1410)
[0f07f308] wingdi vout display error: SetThumbNailClip failed: 0x800706f4
[0f07c670] main video output error: video output creation failed
[0ef90360] main decoder error: failed to create video output

If I run the video without using PyQt, just as:

Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(inputPath)
player.set_media(Media)
player.play()

time.sleep(5) # Or however long you expect it to take to open vlc
while player.is_playing():
     time.sleep(1)
     if 0xFF == ord("q"):
        player.stop()

player.stop()

It works fine. Can anyone point me in the direction of what I might be doing wrong here?



from Running video in Python using VLC and PyQt doesn't start

No comments:

Post a Comment