所以我在这里有一行用于通过python和ffmpeg从电影中转储帧。
subprocess.check_output([ffmpeg, "-i", self.moviefile, "-ss 00:01:00.000 -t 00:00:05 -vf scale=" + str(resolution) + ":-1 -r", str(framerate), "-qscale:v 6", self.processpath + "/" + self.filetitles + "-output%03d.jpg"])
目前它给了我错误:
'CalledProcessError: Command ... returned non-zero exit status 1'
它运行的命令python SAYS是:
'['/var/lib/openshift/id/app-root/data/programs/ffmpeg/ffmpeg', '-i', u'/var/lib/openshift/id/app-root/data/moviefiles/moviename/moviename.mp4', '-ss 00:01:00.000 -t 00:00:05 -vf scale=320:-1 -r', '10', '-qscale:v 6', '/var/lib/openshift/id/app-root/data/process/moviename/moviename-output%03d.jpg']'
但是当我通过ssh运行以下命令时......
'/var/lib/openshift/id/app-root/data/programs/ffmpeg/ffmpeg' -i '/var/lib/openshift/id/app-root/data/moviefiles/moviename/moviename.mp4' -ss 00:01:00.000 -t 00:00:05 -vf scale=320:-1 -r 10 -qscale:v 6 '/var/lib/openshift/id/app-root/data/process/moviename/moviename-output%03d.jpg'
它运作得很好。我究竟做错了什么?我想我误解了子进程字段解析的工作方式......
答案 0 :(得分:3)
除非在shell模式下运行,否则子进程模块几乎不会在其参数中允许任何空白字符。试试这个:
subprocess.check_output(["ffmpeg", "-i", self.moviefile, "-ss", "00:01:00.000", "-t", "00:00:05", "-vf", "scale=" + str(resolution) + ":-1", "-r", str(framerate), "-qscale:v", "6", self.processpath + "/" + self.filetitles + "-output%03d.jpg"])
的引用
"特别注意,由shell中的空格分隔的选项(例如-input)和参数(例如eggs.txt)位于单独的列表元素中,而需要引用的参数或在shell中使用时反斜杠转义(例如包含空格的文件名或上面显示的echo命令)是单个列表元素。"
答案 1 :(得分:2)
传递给check_call
的参数数组格式不正确。 ffmpeg
的每个参数都需要是参数列表中的单个元素,例如
... "-ss 00:01:00.000 -t 00:00:05 -vf ...
应该是
... "-ss", "00:01:00.000", "-t", "00:00:05", "-vf", ...
完整的结果args数组应为:
['ffmpeg', '-i', '/var/lib/openshift/id/app-root/data/moviefiles/moviename/moviename.mp4', '-ss', '00:01:00.000', '-t', '00:00:05', '-vf', 'scale=320:-1', '-r', '10', '-qscale:v', '6', '/var/lib/openshift/id/app-root/data/process/moviename/moviename-output%03d.jpg']