A subtitle file read by Geometry Nodes: give the group the path of an .srt, play the scene, and the cue of the moment is drawn as text.
One file, three small graphs. This page shows how to use it and the few ideas it rests on, not every node.
sample.srt at 4 s. Its <i> tags are gone.file takes the path of the subtitles, an .srt, not of srt_subtitles.bn: the group reads any text it is given, and a .bn draws its own code. sample.srt holds three cues to start with.offset moves every subtitle later, in seconds, size scales the text, and fill gives a mesh, or curves when it is off. material paints the text and font draws it in another font, Blender's own by default.
The group also outputs the cue's text as a string. Plug it into your own String to Curves, or into anything else that takes a string.
Blocks parted by a blank line. Each block holds a number, a timing line and one or more lines of text:
1
00:00:00,500 --> 00:00:03,000
Subtitles read by Geometry Nodes.
2
00:00:03,200 --> 00:00:06,000
<i>From an .srt file,</i>
one cue at a time.
The format has no nesting, so string nodes can read it. A Repeat zone stands in for a loop.
srt_subtitles.bn: srt_cue, srt_seconds
ImportText(path: file) reads the whole file. A text field on a modifier could not hold the line breaks.repeat(blocks, rest: text, …) runs once per block. Each iteration cuts the first block off rest and passes the remainder on. The number of blocks is known before the loop: it is the number of blank lines plus one, from FindInString(…).count.-->. The start is the 12 characters before it, the end the 12 after it, and srt_seconds reads HH:MM:SS,mmm at fixed positions with StringToValue. Because only the arrow is needed, the index line, a byte order mark or extra blank lines change nothing..bn string cannot hold a line break. SpecialCharacters().line_break supplies one.| Trap | What the file does |
|---|---|
FindInString answers 0 when it finds nothing, the same as a match at the first character. | It tests count > 0 before it trusts first_found. |
Import Text keeps the \r of Windows line ends, so blocks are parted by \r\n\r\n. | It looks at the character before the first line break. When that character is blank, every break preceded by it becomes a plain line break. |
One output linked twice into Join Strings counts once, so JoinStrings(…, line_break, line_break) gives a single break. | It makes the blank line with ReplaceString(string: "||", find: "|", replace: line_break). |
HH:MM:SS,mmm --> HH:MM:SS,mmm, one space on each side of the arrow, as the format asks.<i>, <b> and <u> are removed. A <font> tag stays in the text.
The file, sample.srt and the script that renders this page's picture are in examples/tutorials/srt_subtitles/. make srt-check builds the file in Blender and checks its cues against an .srt written with Unix line ends and one written with Windows line ends, then that the text takes its material and its font.