我需要一种方法来了解ffmpeg何时完成其工作。这是我的code:
def on_button_clicked(self, button, progress_bar, filename):
self.execute(progress_bar, filename)
progress_bar.set_text('Encoding')
progress_bar.pulse()
def execute(self, progress_bar, filename):
cmd = ['ffmpeg', '-y',
'-i', filename,
'-r', '30',
'/tmp/test-encode.mkv']
process = sp.Popen(cmd, stdin=open(os.devnull))
progress_bar.set_text('Done')
'完成'永远不会出现。但是,这项工作已经完成。我可以在shell窗口中看到ffmpeg完成了。我怎样才能得到信号?
答案 0 :(得分:0)
尝试强制GTK处理set_text后的待处理事件:
## force the refresh of the screen
while gtk.events_pending():
gtk.main_iteration()
答案 1 :(得分:0)
以下是我最终如何做到这一点:
p = sp.Popen(command, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
def mycallback(p):
p.poll()
if p.returncode is None:
# Waiting for Godot
return True
else:
# Yay, wait is over!
return False
GObject.timeout_add(1000, mycallback, p)