我正在尝试为FFMPEG编写GUI界面。我使用Python的subprocess模块来创建每个转换所需的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刷新的方式有关。是否有一种方法可以访问它?
universal_newlines=True
就能让它工作呢? - Qin Heyang