【发布时间】:2014-12-02 14:18:27
【问题描述】:
我正在尝试通过从 python 子进程库调用 ffmpeg 来创建循环视频文件。这是给我带来问题的部分:
import subprocess as sp
sp.Popen(['ffmpeg', '-f', 'concat', '-i', "<(for f in ~/Desktop/*.mp4; do echo \"file \'$f\'\"; done)", "-c", "copy", "~/Desktop/sample3.mp4"])
使用上面的代码,我收到以下错误:
<(for f in /home/delta/Desktop/*.mp4; do echo "file '$f'"; done): No such file or directory
我确实找到了类似措辞的问题here。但我不确定该解决方案如何适用于解决我的问题。
编辑: 感谢大家的帮助!按照 cmets 中的建议并在其他地方查找,我最终将代码更改为:
sp.Popen("ffmpeg -f concat -i <(for f in ~/Desktop/*.mp4; do echo \"file \'$f\'\"; done) -c copy ~/Desktop/sample3.mp4", shell=True, executable="/bin/bash")
——效果很好。
【问题讨论】:
-
您正在运行
ffmpeg,但重定向是shell 的一项功能。使用shell=True参数强制Popen通过shell 传递它。还要考虑不传递命令和参数数组,而是传递单个字符串。阅读更多here -
如果使用
shell=True,参数需要作为字符串传递,而不是列表。 -
+1 对 Amadan 和 dano 所说的话。您可能还需要明确指出您想要
/bin/bash,而不是默认的/bin/shPopen。 -
请参阅stackoverflow.com/a/24560058/258523 上的讨论,了解为什么
Popen与shell=True的单个字符串参数。