天天看点

python非零返回怎么解决_ffmpeg Python子进程错误返回非零退出状态1

python非零返回怎么解决_ffmpeg Python子进程错误返回非零退出状态1

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...

解决方案

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