2014-10-08 48 views
1

我试图通过从python子进程库调用ffmpeg来创建一个循环视频文件。这里是一个的给我的问题的一部分:在Popen Python中的Bash进程替换

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。但我不确定该解决方案如何适用于解决我的问题。

编辑: 感谢您的帮助!继评论和其他地方的意见后,我最终改变了代码:

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") 

- 哪些工作正常。

+3

您正在运行'ffmpeg',但重定向是shell的一项功能。使用'shell = True'参数来强制'Popen'将它传递给shell。还要考虑不传递一组命令和参数,而是一个字符串。阅读更多[here](https://docs.python.org/2/library/subprocess.html#popen-constructor) – Amadan 2014-10-08 02:10:05

+3

如果使用'shell = True',参数需要作为字符串传递,而不是列表。 – dano 2014-10-08 02:11:19

+4

+1阿马丹和达诺所说的。您可能还需要明确指出您希望'/ bin/bash'而不是'Popen'的默认'/ bin/sh'。 – 2014-10-08 02:12:16

回答

1

继在评论意见,并跳槽我最终的代码更改为此:

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") 

,可呈现正常工作。 - moorej