Page 1 of 1

Code randomly hangs on libvlc_media_player_set_media

Posted: 07 Aug 2021 08:58
by Kwigon
I am trying to create a slideshow style viewer which will display videos and images. However, when testing my approach (code below) the VLC randomly freezes on `self.mediaplayer.set_media(self.media)` in the `Player.play` method. Specifically using the trace module it seems to hang on line 331 in the `vlc.py` file of this library (`vlc_pyqt.py` is my code). The issue seems to be specifically with the `libvlc_media_player_set_media` method.

I also tried to print `vlc.Media.get_state()` to determine if the video/image is being buffered and therefore can not be played but experienced no such event.

Is this a bug or am I doing something wrong? Thanks beforehand for your help everyone!

Trace output:

Code: Select all

vlc_pyqt.py(61): self.mediaplayer.set_media(self.media) --- modulename: vlc, funcname: set_media vlc.py(3467): return libvlc_media_player_set_media(self, p_md) --- modulename: vlc, funcname: libvlc_media_player_set_media vlc.py(6272): f = _Cfunctions.get('libvlc_media_player_set_media', None) or \ vlc.py(6275): return f(p_mi, p_md) --- modulename: vlc, funcname: from_param vlc.py(329): if this is None: vlc.py(331): return this._as_parameter_ --- modulename: vlc, funcname: from_param vlc.py(329): if this is None: vlc.py(331): return this._as_parameter_
Code:

Code: Select all

# Based on https://github.com/oaubert/python-vlc/blob/master/examples/pyqt5vlc.py import platform import sys from PyQt5.QtCore import Qt from PyQt5 import QtWidgets, QtTest, QtGui, QtCore import vlc class Player(QtWidgets.QMainWindow): """A simple Media Player using VLC and Qt""" def __init__(self, master=None): QtWidgets.QMainWindow.__init__(self, master) self.setWindowTitle("Media Player") self.setCursor(Qt.BlankCursor) self.instance = vlc.Instance() # create a basic vlc instance self.mediaplayer = self.instance.media_player_new() # create an empty vlc media player self.media = None self.create_ui() def create_ui(self): """Set up the user interface""" self.widget = QtWidgets.QWidget(self) self.setCentralWidget(self.widget) # In this widget, the video will be drawn self.videoframe = QtWidgets.QFrame() self.vboxlayout = QtWidgets.QVBoxLayout(self.widget) # self.vboxlayout.addSpacing(0) self.vboxlayout.addWidget(self.videoframe) self.widget.setLayout(self.vboxlayout) self.widget.layout().setSpacing(0) self.widget.layout().setContentsMargins(0, 0, 0, 0) # The media player has to be 'connected' to the QFrame (otherwise the # video would be displayed in it's own window). This is platform # specific, so we must give the ID of the QFrame (or similar object) to # vlc. Different platforms have different functions for this if platform.system() == "Linux": # for Linux using the X Server self.mediaplayer.set_xwindow(int(self.videoframe.winId())) elif platform.system() == "Windows": # for Windows self.mediaplayer.set_hwnd(int(self.videoframe.winId())) elif platform.system() == "Darwin": # for MacOS self.mediaplayer.set_nsobject(int(self.videoframe.winId())) def play(self, media_path, display_time_ms=None): self.media = self.instance.media_new(media_path) print(self.media.get_state()) self.media.parse() # parse the metadata of the file print(self.media.get_state()) self.mediaplayer.set_media(self.media) self.mediaplayer.play() if not display_time_ms: QtTest.QTest.qWait(self.media.get_duration()) else: QtTest.QTest.qWait(display_time_ms) def main(): """Entry point for our simple vlc player""" app = QtWidgets.QApplication(sys.argv) player = Player() player.showFullScreen() while True: player.play("/data/demo_1080p.mp4") player.play("/data/demo_1080p.mp4") player.play("/data/demo_1080p.mp4", display_time_ms=4000) player.play("/data/bam2.jpg", display_time_ms=4000) player.play("/data/dat.png", display_time_ms=4000) player.play("/data/kino.jpg", display_time_ms=4000) player.play("/data/demo_720p.mp4", display_time_ms=4000) player.play("/data/kino.jpg", display_time_ms=4000) sys.exit(app.exec_()) if __name__ == "__main__": main()
I am using the latest version of both the `python-vlc` library and VLC itself available to RPi 4.

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 09 Aug 2021 04:10
by mfkl
Are the logs saying anything?

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 18 Aug 2021 15:38
by Kwigon
There's nothing relevant in journalctl. I'm not sure how to view VLC logs when running the python-vlc bindings. Looked into the documentation and couldn't find anything. Do you have any specific logs in mind?

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 20 Aug 2021 17:53
by Rémi Denis-Courmont
He meant the VLC logs, not the Linux logs.

I would guess that the current input got stuck for whatever reasons. Best would be a symbolic threaded stack trace.

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 25 Aug 2021 15:21
by Kwigon
Took some time to figure out how to view the vlc log using python-vlc bindings. Here are the last few hundred lines from the log I got:
https://pastebin.com/zsNyArcv

The numbers represent when the next `play` call was made (1 through 8 ). To my untrained eye it seems like it just stopped without any errors.

How do I do a symbolic threaded stack trace please? I am unfamiliar with such technique and could not find anything when searching for such term.

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 25 Aug 2021 18:18
by Rémi Denis-Courmont
That heavily depends on your system. Also it seems that you're using some external plug-ins, which are not accounted for.

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 15 Dec 2021 11:53
by Kwigon
The issue seems to have been caused by one of the pictures being too large (~8K), therefore the screen froze as VLC tried to load it and after 10 seconds it just continued with the next one. Solved by limiting picture resolution, which is not ideal but is good enough in my usecase.

Re: Code randomly hangs on libvlc_media_player_set_media

Posted: 02 Aug 2022 11:07
by Krilya
After messing around with python-vlc for quite a while, I personally found that the set_mrl() method is more reliable than set_media()