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
    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 = ''
      if newline != '':
        sub = sub + newline + '\n'


To produce the fotoromanzo just run:

python video.avi output_dir

This entry was posted in software and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s