我正在尝试为FFMPEG
. 我正在使用 pythons 子进程为我想要的每个转换创建一个 ffmpeg 进程。这很好用,但我也想要一种方法来获取转换的进度,无论它是否失败等等。我想我可以通过访问进程的标准输出来做到这一点,如下所示:
打电话subprocess.Popen()
# Convert - Calls FFMPEG with current settings. (in a seperate
# thread.)
def convert(self):
# Check if options are valid
if self.input == "" or self.output == "":
return False
# Make the command string
ffmpegString = self.makeString()
# Try to open with these settings
try:
self.ffmpeg = subprocess.Popen(ffmpegString, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except OSError:
self.error.append("OSError: ")
except ValueError:
self.error.append("ValueError: Couldn't call FFMPEG with these parameters")
# Convert process should be running now.
并阅读stdout
:
convert = Convert()
convert.input = "test.ogv"
convert.output = "test.mp4"
convert.output_size = (0, 0)
convert.convert()
while 1:
print convert.ffmpeg.stdout.readline()
这有效,但是 ffmpeg 的状态不显示。我假设它与 ffmpeg 刷新它的方式有关。有没有办法访问它?