[英]Python : call ffmpeg command line with subprocess
I'm trying to call simple ffmpeg command line with subprocess.call. 我正在尝试使用subprocess.call调用简单的ffmpeg命令行。 (Example :
ffmpeg -i input\\video.mp4 -r 30 input\\video.avi
) (示例:
ffmpeg -i input\\video.mp4 -r 30 input\\video.avi
)
By typing directly the ffmpeg command it works, but when I try to call it with subprocess.call : subprocess.call('ffmpeg -i input\\video.mp4 -r 30 input\\video.avi', shell=True)
there is no error, but it doesn't produce anything. 通过直接键入ffmpeg命令,它可以工作,但是当我尝试使用
subprocess.call('ffmpeg -i input\\video.mp4 -r 30 input\\video.avi', shell=True)
调用它时: subprocess.call('ffmpeg -i input\\video.mp4 -r 30 input\\video.avi', shell=True)
有没有错误,但不会产生任何结果。
Any idea where can be the problem? 知道哪里可能是问题吗? (I'm working with python 3.4 or 2.7, I tried both)
(我正在使用python 3.4或2.7,我都尝试过)
Finally found the problem : when you are using subprocess you MUST use 终于发现了问题:使用子流程时,必须使用
/
for your files location instead of 为您的文件位置而不是
\
EDIT : or you can use raw-string literals -> r'ffmpeg -i input\\video.mp4 ...'
(notice: r'') or you can double them ' \\\\
' Thanks to JF Sebastian 编辑 :或者您可以使用原始字符串文字->
r'ffmpeg -i input\\video.mp4 ...'
(注意:r''),也可以将它们加倍' \\\\
' 感谢JF Sebastian
x=subprocess.Popen('ffmpeg -i input\video.mp4 -r 30 input\video.avi', shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output,err=x.communicate()
if output:
print "success ",output
else:
print "error ",err
You can try this and check output and errors if any. 您可以尝试此操作,并检查输出和错误(如果有)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.