【发布时间】:2018-09-19 12:46:50
【问题描述】:
我有一个 Python 3.6 程序,它使用 Popen 命令从 ffmpeg 库中调用 ffplay。
我想发送ffplay 击键,以便我可以控制播放。但似乎什么也没有发生。举个例子:
import subprocess
import time
# Array with the command in it
my_command = ("ffplay", "-nodisp", "-autoexit", "examples/sounds/Fantascape_Looping.mp3")
# Open a subprocess
my_subprocess = subprocess.Popen(my_command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Wait 2 seconds
time.sleep(2)
# Try to send an escape:
print("Attempt to send and 'escape' to stop the sound")
my_subprocess.stdin.write(b'\x1b')
# Wait and see what happens
print("Should no longer hear anything")
time.sleep(5)
我听音乐 7 秒,而不是 2 秒。代码有什么问题?
【问题讨论】: