简体   繁体   English

如何从 Python 3 中的 vlc 模块中使控制台 output 静音

[英]How to silence console output from vlc module in Python 3

(Xubuntu 18.04, Python 3.6.9) (Xubuntu 18.04, Python 3.6.9)

I am working on a little application for myself with very simple usage of the vlc module.我正在为自己开发一个小应用程序,非常简单地使用 vlc 模块。 It's a console-based application using curses, and vlc is interjecting its output in the middle of my terminal interface.这是一个使用curses的基于控制台的应用程序,vlc在我的终端界面中间插入了它的output。 I can't figure out how to silence it.我不知道如何让它静音。 Have read libvlc docs, nothing about it that I can find.已阅读 libvlc 文档,我找不到任何关于它的信息。 Have tried the advice from this similar question , no success after setting sys.stderr = open('stderr.txt', 'w+') .尝试过这个类似问题的建议,设置sys.stderr = open('stderr.txt', 'w+')后没有成功。 Have not been able to locate anything in the libvlc docs or running vlc -H .无法在 libvlc 文档或运行vlc -H中找到任何内容。 I don't really care if I'm able to access the output;我真的不在乎我是否能够访问 output; I just need it to not print in the console.我只需要它不在控制台中打印。

Here is all my VLC-related code, probably unnecessary in this case:这是我所有与 VLC 相关的代码,在这种情况下可能不需要:

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?有谁知道我能做什么?

From vlc -H :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 实例,并将 stderr 重定向到/dev/null即可。
vlc_instance = vlc.Instance('--no-xlib -q > /dev/null 2>&1')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM