我有一个代码,可以成功打开VLC,全屏幕,添加媒体等,所有这些都一行 - 例如(摘自较长的代码):
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","--one-instance","--fullscreen","--playlist-enqueue",clips[selection],speed[speed_selection]])
该特定行在循环内。我想打开循环的vlc ,然后添加媒体,然后在中选择速度,如(摘录):
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","--fullscreen"])
timer = 0
while timer <= 19:
selection = randint(1, 11)
speed_selection = randint(1, 4)
p = subprocess.Popen(#???? is this even the right command?)([#Something here to refer to vlc??,"--playlist-enqueue",clips[selection],speed[speed_selection]])
timer += 1
我似乎找不到或找出与已经打开的VLC播放器通信的语法。我会收到错误'FilenotFoundError:[WinError 2]系统无法找到指定的文件'每次尝试任何事情时,这是有道理的,因为我没有正确地告诉Popen在哪里打开这些东西!
可能是p = subprocess.popen()是不正确的语法,或者在括号内我需要以某种方式参考VLC而不打开其他实例?
任何提出的建议。
完整代码:
clips = {1: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 1.mp4", 2: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 2.mp4", 3: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 3.mp4", 4: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 4.mp4", 5: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 5.mp4", 6: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 6.mp4", 7: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 7.mp4", 8: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 8.mp4", 9: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 9.mp4", 10: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 10.mp4", 11: "file:///C:/Users/Dan/Pictures/Bouchra UNI/Studio Practice 3/Moving drawing mp4s/for PYTHON short clips as mp4/clip 11.mp4"}
speed = {1: "--rate=1.0", 2: "--rate=1.5", 3: "--rate=2.0", 4: "--rate=0.5"}
import subprocess
from random import randint
p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","--fullscreen"])
timer = 0
while timer <= 19:
selection = randint(1, 11)
speed_selection = randint(1, 4)
p = subprocess.Popen(["--playlist-enqueue",clips[selection],speed[speed_selection]])
timer += 1
我做了一个python模块来解决此问题。televlc
~$ pip install televlc
创建VLC实例和接口,然后连接
import televlc
# Initialize the vlc object
vlc = televlc.VLC()
# Open a VLC instance and create the telnet interface
vlc.start_telnet_interface()
# Connect to the telnet interface
vlc.connect_to_telnet_interface()
# Run a command (volume up)
vlc.do(["volup", "50"])
# Disconnect from telnet interfac
vlc.disconnect_from_telnet_interface()
# or
vlc.do(["exit"])
# or end VLC instance and telnet interface
vlc.do(["shutdown"])
连接到现有VLC实例和接口
这是创建现有实例并在脚本之外连接的命令
~$ vlc --extraintf --telnet --telnet-password myPassword --telnet-host myHost --telnet-port myPort
import televlc
# Set the interface data
PASSWORD = myPassword
HOST = myHost
PORT = myPort
# Initialize the vlc object
vlc = televlc.VLC(PASSWORD, HOST, PORT)
# Run a command
command = ["volup", "50"]
vlc.do(command)
# Quit
vlc.disconnect_from_telnet_interface()