我有一个代码可以成功地打开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播放器进行通信的语法。我收到错误&#39; FileNotFoundError:[WinError 2]系统无法找到指定的文件&#39;我每次尝试任何事情都是有道理的,因为我没有正确地告诉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
答案 0 :(得分:0)
我做了一个python模块来解决这个问题; televlc
~$ pip install televlc
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 --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()