gpt4 book ai didi

python - ffmpeg|sed 命令的 subprocess.call 格式?

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:50 30 4
gpt4 key购买 nike

这些是我想在 python 中使用 subprocess.call 执行的命令

 1. ffmpeg -i filename 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p"

filePath = frames/FRAME%05d.png
2. avconv -r 24 -i filePath -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' -s 1920x1080 -c:v libx264 outPath

我还没有开始做第二个,但这是我对第一个的尝试

subprocess.call(['ffmpeg', '-i', inputV , '2','>','&1', '|', ' sed', '-n', '"s/.*, \(.*\) fp.*/\1/p"'])

这是错误

[NULL @ 0x915ce0] Unable to find a suitable output format for '2'
2: Invalid argument

我也不确定 filePath 变量分配,因为该值包含通配符

最佳答案

快速修复:添加shell=True选项,因为您正在使用 shell 功能。

Longfix:写一个正确的subprocess.Popen命令,并摆脱 sed : 直接用Python来做:

import re
r = re.compile(".*, (.*) fp.*")
p=subprocess.Popen(['ffmpeg', '-i', inputV],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
while True:
l = p.readline()
if not l:
break # end of process
s = r.sub(l,r"\1")
if l!=s: # substitution worked, print it
print(s)
rc = p.wait() # get return code

所以你没有使用shell=True像这样,你执行 sed python 中的过滤器:您的代码不需要 sed不再了。

stderr=subprocess.STDOUT照顾stderr重定向于stdout

关于python - ffmpeg|sed 命令的 subprocess.call 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42609546/

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