In my Python script I intercept KeyboardInterrupts to ensure that the script can finish what its doing before shutting down. However I've found that FFMPEG, which I'm using by triggering commandline commands, immediately ends its current prosessing, before then leading into my script's shutdown processes.
The code below shows my KeyboardInterrupt handling system.
prepareToStop = 0
while prepareToStop == 0:
t = threading.Thread(target=main_loop, args=[instanceID])
try:
t.start()
t.join() # wait for the threading task to end
except KeyboardInterrupt:
prepareToStop = 1
And the code below creates and runs the FFMPEG commands:
command = "\"" + ffmpeg + "\" -y -i " + "uploaded/" + videofile_name + " -c:v " + codec + " " + commandDimensions + " " + commandCompression + " -c:a copy" + commandAspect + " "+str(outputFilePath) #bash command to proccess file
print("Running command: " + command)
res = os.system(command) #run command
What I'm looking for is a way to ensure that FFMPEG ignores KeyboardInterrupts, so that the system can handle shutdown process after it has completed.
Edit:
I've identified that this is an issue with FFMPEG. I need it to ignore external commands while processing. I've seen examples suggesting that using '-nostdin' can do this, however it appeared to have no effect when I added it to the command. I intended on posting about this as a seperate question, but my account is apparently restricted.