I want to convert a video with subtitles in a comic made of photos. Text are extracted from the subtitle file and then added to video frames.
Objects and people in the frames can be tagged and linked to web pages. Thanks to stipple you can add reference to the commercia products you see in the picture (the same way you tag a friend in facebook)
Python script:
import sys
import os
subfile = open(sys.argv[1], "r").readlines()
videofile = sys.argv[2]
outputdir = sys.argv[3]
time = ''
sub = ''
frame = 0
for line in subfile:
if '-->' in line:
word = line.split()
time = word[0].replace(',','.')
#line[:-2] remove endofline chars
else:
newline = line[:-2]
newline = line
newline = newline.strip()
newline = newline.replace("<i>","")
newline = newline.replace("</i>","")
newline = newline.replace("'","\\'")
if newline.isdigit():
newline = newline+'\n'
frame = frame + 1
frame_str = "%04d"%frame
#print sub
#print time+" "+newline
os.system("ffmpeg -vframes 1 -ss "+time+" -i "+videofile+" ./temp.jpg")
os.system("convert ./temp.jpg -pointsize 40 -gravity south -stroke '#000C' -strokewidth 2 -draw \"text 0,0 '"+sub+"'\" -stroke none -fill white -draw \"text 0,0 '"+sub+"'\" ./"+outputdir+"/"+frame_str+"_sub.jpg")
sub = ''
else:
if newline != '':
sub = sub + newline + '\n'
To produce the fotoromanzo just run:
python fotoromanzo.py subtitle.srt video.avi output_dir