This python script identifies all movies with mp4 extension and, if they have subtitles in srt format, converts the subtitle encoding to utf-8 (without this conversion you will get error message) and starts building the movie with the subtitle embedded.
for filename in glob.glob("*.mp4"):
print(str(filename))
if 'wsubs' not in filename:
for legenda in glob.glob(filename.replace(".mp4",".srt")):
try:
with open(legenda, 'r') as arquivo_orig:
conteudo = arquivo_orig.read()
with open(legenda, 'w', encoding='utf-8') as novo_arquivo:
novo_arquivo.write(conteudo)
except Exception as e:
print("Já codificado")
print(str(legenda))
os.system('ffmpeg -i "' + str(filename) + '" -vf subtitles="' + str(legenda) + '" -maxrate 2000000 -crf 20 "' + str(filename.replace('.mp4','-wsubs.mp4')) + '"')
The end result will be a subtitled movie with the expression "wsubs" at the end of the name. The original files will be preserved.
I am not entirely sure what you are asking as it looks like you have answered your own question. So if it is an opinion on how to achieve what I think you are doing, this is how I would do it. [I would have liked to have left this as a comment but my reputation is not high enough.]
The primary difference between the scripts is that I use subprocess to execute the ffmpeg command. I also pass the subtitles file though a pipe as with my experience; ffmpeg does not like certain filenames within the -vf argument. While not an important difference; I also use the os library to handle my filename manipulations.