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?
CodePudding user response:
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).
CodePudding user response:
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)