Python 将Popen与ffmpeg一起使用时的空行输出
我正在尝试从命令获取信息输出:Python 将Popen与ffmpeg一起使用时的空行输出,python,ffmpeg,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-无(无,无) 我尝试了subprocess,并在前面尝试了os.popen command = 'ffmpeg -i 2019-04-22_
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
-无(无,无)
我尝试了subprocess,并在前面尝试了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)
此代码将所有结果保存在文件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()
小心,来自ffmpeg的“信息”会在stderr流FWIW中返回…谢谢!实际上,我刚刚解决了subprocess的问题。check_output!:)请随意为您自己的问题添加答案:)