从ffmpeg获取实时输出以在进度条(PyQt4,stdout)中使用

从ffmpeg获取实时输出以在进度条(PyQt4,stdout)中使用,第1张

从ffmpeg获取实时输出以在进度条(PyQt4,stdout)中使用

我发现从子进程获取动态反馈/输出的唯一方法是使用类似pexpect的方法:

#! /usr/bin/pythonimport pexpectcmd = "foo.sh"thread = pexpect.spawn(cmd)print "started %s" % cmdcpl = thread.compile_pattern_list([pexpect.EOF,  'waited (d+)'])while True:    i = thread.expect_list(cpl, timeout=None)    if i == 0: # EOF        print "the sub process exited"        break    elif i == 1:        waited_time = thread.match.group(1)        print "the sub process waited %d seconds" % int(waited_time)thread.close()

被调用的子进程foo.sh只是等待10到20秒之间的随机时间,这是它的代码:

#! /bin/shn=5while [ $n -gt 0 ]; do    ns=`date +%N`    p=`expr $ns % 10 + 10`    sleep $p    echo waited $p    n=`expr $n - 1`done

您将要使用一些正则表达式,使其与从ffmpeg获得的输出相匹配,并对其进行某种计算以显示进度条,但这至少将为您提供ffmpeg的未缓冲输出。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5644593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存