gpt4 book ai didi

python - 使用带有 ffmpeg 的 Popen 时的空行输出

转载 作者:行者123 更新时间:2023-12-04 22:50:17 27 4
gpt4 key购买 nike

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

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)

最佳答案

此代码将所有结果保存在文件 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()

关于python - 使用带有 ffmpeg 的 Popen 时的空行输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56329834/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com