Search code examples
pythonpython-3.xvlclibvlc

How to silence console output from vlc module in Python 3


(Xubuntu 18.04, Python 3.6.9)

I am working on a little application for myself with very simple usage of the vlc module. It's a console-based application using curses, and vlc is interjecting its output in the middle of my terminal interface. I can't figure out how to silence it. Have read libvlc docs, nothing about it that I can find. Have tried the advice from this similar question, no success after setting sys.stderr = open('stderr.txt', 'w+'). Have not been able to locate anything in the libvlc docs or running vlc -H. I don't really care if I'm able to access the output; I just need it to not print in the console.

Here is all my VLC-related code, probably unnecessary in this case:

def vlc_init():
    global vlc_instance, media_player
    vlc_instance = vlc.Instance('--no-xlib') # VLC asked me to pass '--no-xlib' *shrug*
    media_player = vlc_instance.media_player_new()

def set_new_media(media_path):
    media = vlc_instance.media_new(media_path)
    media_player.set_media(media)

Does anyone know what I can do?


Solution

  • From vlc -H:

    Console logger (console)
     -q, --quiet, --no-quiet        Be quiet
                          (default disabled)
       Turn off all messages on the console.
    

    So yea, just call your vlc instance with one of those flags enabled, and redirect stderr to /dev/null for good measure.
    vlc_instance = vlc.Instance('--no-xlib -q > /dev/null 2>&1')