在ffmpeg中使用Popen时空行输出

时间:2019-05-27 16:49:58

标签: python ffmpeg

我正在尝试从命令获取信息输出:

ffmpeg -i 2019-04-22_16-45-14.mp4 -loop 1 -i image.png -an -filter_complex "blend=difference:shortest=1,blackframe=99:32" -f null -

在命令行中尝试此命令时-信息在那里,但是当我尝试使用Popen时-什么都没有(无,无)

我已经尝试了子流程,并且更早地尝试了os.popen

command = 'ffmpeg -i 2019-04-22_16-45-14.mp4 -loop 1 -i image.png -an -filter_complex "blend=difference:shortest=1,blackframe=99:32" -f null -'
subproc = subprocess.Popen(command.split(' '), shell=True)
x = subproc.communicate()
print(x)

1 个答案:

答案 0 :(得分:0)

此代码将所有结果保存在文件out.txt中。如果有任何错误,请转到err.txt:

with open('out.txt','w+') as fout:
    with open('err.txt','w+') as ferr:
        proc = subprocess.call(['ffmpeg.exe', '-i', '20200522_0755.mp4', '-r', '1', '-loop', '1', '-i', 'livre.jpg', '-an', '-filter_complex', 'blend=difference:shortest=1,blackframe=89:32', '-f', 'null', '-'],stdout=fout,stderr=ferr)
        # reset file to read from it
        fout.seek(0)
        # save output (if any) in variable
        output=fout.read()
        # reset file to read from it
        ferr.seek(0) 
        # save errors (if any) in variable
        errors = ferr.read()