Skip to content

Instantly share code, notes, and snippets.

@xiaojay
Created October 22, 2013 03:55
Show Gist options
  • Save xiaojay/7094996 to your computer and use it in GitHub Desktop.
Save xiaojay/7094996 to your computer and use it in GitHub Desktop.
自动给coursera课程添加字幕加班
#coding=utf-8
import sys, os, subprocess
dir_ = sys.argv[1]
command = 'mencoder -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4 -sub "%s" -subfont-text-scale 1.8 -subpos 95 -sub-bg-alpha 240 -utf8 -o "%s" "%s"'
for fn in os.listdir(dir_):
name, ext = os.path.splitext(fn)
mp4_file = os.path.join(dir_, fn)
srt_file = os.path.join(dir_, '%s.srt'%name)
if ext == '.mp4' and os.path.exists(srt_file):
print fn
output_dir = os.path.join(dir_, 'srt')
if not os.path.exists(output_dir):
os.mkdir(output_dir)
output_file = os.path.join(output_dir, fn)
c = command%(srt_file, output_file, mp4_file)
subprocess.call(c, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment