2007-09-02

Lyrics -> video clip subtitles converter

A note as a piece of memory.
I wanted to suit lyrics to video clip of "Beauty Girls" song performed by Sean Kingston. I downloaded clip, lyrics, and developed a script which with interaction with me, generated subtitle file. It was something about transformation from

your way to beautiful girl
what's why it will never work
you had me suicidal, suicidal
when you say it's over

to

{410}{514}your way to beautiful girl
{524}{575}that's why it will never work
{586}{691}you had me suicidal, suicidal
{699}{763}when you say it's over


Uh, the script is here:

#!/bin/sh
 
INTERVAL=0
cat /dev/null > /tmp/sean.txt
DIV=41708375
T=`date +%s%N`
 
TEXT="/home/user/Sean_Kingston-Beautiful_Girls.txt"
 
LINE=0
while true
do
  LINE=`expr $LINE + 1` LINETEXT=`head -${LINE} $TEXT | tail -1`
  echo $LINETEXT
  read
  TIMES=`date +%s%N`
  read
  TIMEE=`date +%s%N`

  START=`expr $TIMES - $T`
  START=`expr $START / $DIV`

  END=`expr $TIMEE - $T`
  END=`expr $END / $DIV`

  echo "{${START}}{${END}}${LINETEXT}" >> /tmp/sean.txt
done  
exit 0


Explanation:
DIV is a variable to convert nanoseconds produced by date %s%N to frames per second in my particular video clip (26.976 fps).
Run clip and this script at the same moment in nonoverlapping windows. A line of text appears on console. Then press Enter when you hear the dialog/text, and again Enter when you want to clear screen from the text. Every line of text needs two Enters.

Well synchronized subtitles require some training.

No comments: