Skip to content

Instantly share code, notes, and snippets.

@wangmuy
Created May 16, 2018 06:30
Show Gist options
  • Save wangmuy/730a362fbc5a522d54d3b695bc1bae85 to your computer and use it in GitHub Desktop.
Save wangmuy/730a362fbc5a522d54d3b695bc1bae85 to your computer and use it in GitHub Desktop.
Burn subtitle into video
#!/usr/bin/env python
import os
import sys
import shlex
import subprocess
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("orig_dir")
parser.add_argument("baked_dir")
args = parser.parse_args()
orig_dir = args.orig_dir
baked_dir = args.baked_dir
mp4_files = [f for f in os.listdir(orig_dir) if f.endswith('.mp4')]
for f in mp4_files:
try:
srt_file = f[:-4] + ".en.srt"
baked_file = baked_dir + '/' + f
# cmder bash on windows: replace for ' and ,
srt_replace = srt_file.replace("'", "\\\\\\\'").replace(",", "\\,")
subprocess.check_call(['d:/ffmpeg/bin/ffmpeg.exe', '-i', f, '-vf', 'subtitles='+srt_replace, baked_file])
except Exception as e:
print(e)
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment