I am running ffmpeg in python as a subprocess. I want to burn the subtitles into a video. Just using ffmpeg (commandline without python in windows) the following works:
ffmpeg.exe" -y -i "input_file" -vf "subtitles= \'input_file_path\' :si=0" -acodec copy "output_file_path"
the \ escape characters are required by ffmpeg for special characters within a filter, However trying to replicate this within a python subprocess has proved problematic, here is one of many failed attempts:
command = ["ffmpeg.exe","-y","-i","input_file_path","-acodec","copy","-vf","subtitles=",'\"'+"input_file_path"+'\"',output_file_path]print(command)proc = subprocess.Popen(command, stderr=PIPE,stdin=subprocess.PIPE,universal_newlines=True,encoding='utf-8')
I have also tried making a raw string, another attempt:
command = ["ffmpeg.exe","-y","-i","input_file_path","-acodec","copy","-vf","subtitles=",r'\"'+"input_file_path"+r'\"',output_file_path]
this results in an error in ffmpeg, although the syntax looks ok:
Unable to find a suitable output format for '\"input_file_path\"'\"C:/temp/two.mp4\": Invalid argument
ffmpeg seems to want to treat it as the output.I need to get the right combination of Python escape characters and ffmpeg escape characters. Any ideas?