问题
So I have a line here that is meant to dump frames from a movie via python and 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"])
And currently it's giving me the error:
'CalledProcessError: Command ... returned non-zero exit status 1'
The command python SAYS it's running is:
'['/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']'
But when I run the following command via 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'
It works just fine. What am I doing wrong? I think I'm misunderstanding the way subprocess field parsing works...
回答1:
The subprocess module does almost never allow any whitespace characters in its parameters, unless you run it in shell mode. Try this:
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"])
Here is a cite from the python docs.
"Note in particular that options (such as -input) and arguments (such as eggs.txt) that are separated by whitespace in the shell go in separate list elements, while arguments that need quoting or backslash escaping when used in the shell (such as filenames containing spaces or the echo command shown above) are single list elements."
回答2:
The argument array you pass to check_call is not correctly formatted. Every argument to ffmpeg needs to be a single element in the argument list, for example
... "-ss 00:01:00.000 -t 00:00:05 -vf ...
should be
... "-ss", "00:01:00.000", "-t", "00:00:05", "-vf", ...
The complete resulting args array should be:
['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']
来源:https://stackoverflow.com/questions/25067927/ffmpeg-python-subprocess-error-returned-non-zero-exit-status-1