如何使VLC与subprocess.Popen实时运行

时间:2019-01-01 09:21:40

标签: python-2.7

我写了一个简短的脚本来控制两个VLC实例。从终端运行良好。我正在Linux Ubuntu上运行它(在我的Mac osx上,python部分运行正常)。

这些是用于控制VLC的终端命令:

vlc -I oldrc --rc-unix=/home/user/documents/Sockets/socket1.sock
vlc -I oldrc --rc-unix=/home/user/Documents/Sockets/socket2.sock
echo enqueue /home/user/Documents/DualscreenVLC/videos/MVI_2534.MP4 | nc -U /home/user/Documents/sockets/socket1.sock
echo play | nc -U /home/user/Documents/Sockets/socket1.sock

要从Python脚本运行此命令,我想利用subprocess.Popen命令。这是哪里出了问题。

我的python脚本:

def RunVLCCommand(cmd):
    print "running"
    p=subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE)

RunVLCCommand('vlc -I oldrc --rc-unix=/home/luukschroder/Documents/Sockets/socket1.sock')
time.sleep(2)
RunVLCCommand('vlc -I oldrc --rc-unix=/home/luukschroder/Documents/Sockets/socket2.sock')
time.sleep(2)
RunVLCCommand('echo enqueue /home/luukschroder/Documents/DualscreenVLC/videos/MVI_2534.MP4 | nc -U /home/luukschroder/Documents/Sockets/socket1.sock')
time.sleep(2)

当我从终端运行脚本时,它将运行所有命令,并等待2秒。我明白了:

running 
VLC media player 3.0.4 Vetinari (revision 3.0.4-0-gf615db6332)
[0000560b933320c0] oldrc interface: Removing dead UNIX socket: /home/luukschroder/Documents/Sockets/socket1.sock
[0000560b932595a0] main playlist: playlist is empty
running 
VLC media player 3.0.4 Vetinari (revision 3.0.4-0-gf615db6332)
[0000560150e6a5a0] main playlist: playlist is empty
running
running
running
running
finished

然后出现两个错误:

[00007f52480f86e0] xcb_window window error: X server failure
[00007f64b40f8640] xcb_window window error: X server failure

然后,VLC播放器才开始播放。 如何确保VLC与脚本同时运行?

编辑:我认为我在调用subprocess.Popen ...时不了解stdout,stdin和stderr的工作方式。

0 个答案:

没有答案