简体   繁体   中英

subprocess in python does not produce the output

I have this ffmpeg command:

ffmpeg -y -i 6.mp4 -vf scale=1280:-2,setsar=1:1 -c:v libx264 -c:a copy 720p.mp4

and I want to implement it via python code. for this I used subprocess function and I use the following code for this:

subprocess.call(['ffmpeg.exe','-y','-i', pname1,'-vf','scale=','1280:-2','setsar=','1:1','-c:v', 'libx264', '-c:a', 'copy', pname2])

pname1 and pname2 are the names of input and output files. this program is running without any error, but it produces nothing. do you know what is the problem?

To see what the process is doing you can capture the output by replacing:

subprocess.call(["command"])

with:

subprocess.check_output(["command"], stderr=subprocess.STDOUT)

See https://docs.python.org/3.9/library/subprocess.html#subprocess.check_output

So your call would become:

ffmpeg_output = subprocess.check_output(
    ['ffmpeg.exe','-y','-i', pname1,'-vf','scale=','1280:-2','setsar=','1:1','-c:v', 'libx264', '-c:a', 'copy', pname2],
    stderr=subprocess.STDOUT
)
print(ffmpeg_output)

The correct syntax is:

subprocess.call(['ffmpeg.exe', '-y', '-i', pname1, '-vf', 'scale=1280:-2,setsar=1:1', '-c:v', 'libx264', '-c:a', 'copy', pname2])

Each element in the list (after the first one) represents an argument.
The sperate arguments to FFmpeg may be identified by the spaces between them (when executing FFmpeg in command line).

When executing you original command, I am getting an error message:

[NULL @ 0000020fb89bc2c0] Unable to find a suitable output format for '1280:-2' 1280:-2: Invalid argument

The error message is printed to stderr (usually printed to the console).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM