I'm trying to automate concatenating a folder of (correctly formatted) mp4 video files.
(This edited version of my question reduces the problem to its lowest level of my confusion. The original title asked about the differences between subprocess.call and subprocess.run but it turns out the problem was elsewhere.)
Why does
subprocess.call('ffmpeg -hide_banner -loglevel error -i movie1.mp4 -i movie2.mp4 -i credits.mp4 \
-filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" "output.mp4"',shell=True)
work fine (where s is a string of inputs, and count is the number of inputs), but
#python3
#makeFinalExample.py
import subprocess
s = '-i movie1.mp4 -i movie2.mp4 -i credits.mp4'
count = 3
print(f's prints out as: {s}')
commandList = ['ffmpeg',
'-hide_banner',
'-loglevel',
'error',
#str(s),
'{0}'.format(s),
'-filter_complex',
"[0:v:0][0:a:0][1:v:0][1:a:0]concat=n={0}:v=1:a=1[outv][outa]".format(count),
'-map',
"[outv]",
'-map',
"[outa]",
"output.mp4"]
print(f'the command list prints out as {commandList}')
subprocess.run(commandList)
gets the error (whether the string is delivered as str(s), or in the formatting shown...
Unrecognized option 'i movie1.mp4 -i movie2.mp4 -i credits.mp4'.
Error splitting the argument list: Option not found
Here is a printout of the input string
-i movie1.mp4 -i movie2.mp4 -i credits.mp4
And here is a printout of the commandList
['ffmpeg', '-hide_banner', '-loglevel', 'error', '-i movie1.mp4 -i movie2.mp4 -i credits.mp4', '-filter_complex', '[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=3:v=1:a=1[outv][outa]', '-map', '[outv]', '-map', '[outa]', 'output.mp4']
shell=Trueand the formatting used when you don't have that keyword argument.subprocess.runis basically a replacement forsubprocess.callbut it doesn't differ in this particular aspect. (They differ in what they return;callsimply returns the status code, whilerunreturns aCompletedProcessobject which includes the status code as an attribute, but also various other pieces of information about the process you ran.)'{0}'.format(s)is a clumsy way to writestr(s)or simplysif the variable is already a string); I don't think this error is reproducible.s. Please make sure that your code sample is executable, and that the error message is reproducible.