Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Last active January 24, 2018 09:37
Show Gist options
  • Save pepijndevos/600039b1e0a3cc2ea868d0967196c837 to your computer and use it in GitHub Desktop.
Save pepijndevos/600039b1e0a3cc2ea868d0967196c837 to your computer and use it in GitHub Desktop.
Generate an image for every subtitle line
ffmpeg -y -txt_format text -i sw.mkv out.srt;
mkdir frames;
mkdir memes;
timestamps=$(grep -oE " [0-9]{2}:[0-9]{2}:[0-9]{2}" out.srt);
i=0;
for ts in $timestamps
do
ffmpeg -y -ss $ts -copyts -i sw.mkv -vf subtitles=sw.mkv -frames:v 1 frames/out$i.jpg;
convert frames/out$i.jpg -background White -pointsize 32 label:'Can we really turn every line from the prequels into a meme?' +swap -gravity Center -append memes/meme$i.jpg;
((i = i + 1))
done
import srt
import csv
with open("out.srt", "r", encoding='iso-8859-1') as f:
text = f.read()
subs = srt.parse(text)
with open('subs.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
for sub in subs:
print(sub)
writer.writerow([sub.index, sub.content, sub.start, sub.end, 3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment