Random video player from subtitles file

Hi there,

I’m totally new to touchdesigner although I do have some familiarity with MaxMSP/Jitter.

What i’m trying to do is have a patch which reads a subtitles file, and when certain keywords come up in the text it will select a random video from a specific folder and send it to an output. The video is 4k but I have a pretty good graphics card (GeForce GTX 1080).

So basically a stream of data, something that checks to see if any of the words in that line match any of the keywords, if so then make random selection from matching folder, if not then continue to next video in current folder or something like that.

Hope that makes sense. I see there are some tutorials on video playback and selecting a random video index so that shouldn’t be too hard, but it would good if anyone has any ideas on how to read out the subtitles file and check for the matching words>send the trigger to select the video.

Any help very much appreciated,

I would do this with python.

You create a python extension class on a ContainerCOMP and call it something like ‘SubtitleReader’.
[url]https://matthewragan.com/2016/07/14/python-in-touchdesigner-extensions-touchdesigner/[/url]

You’d then create a class variable called something like current_subtitle_index on the SubtitleReader class that keeps track of where you are up to in the subtitle file.

You can set up a public class function on the SubtitleReader called something like ‘NextSubtitle’ which will use a python library (eg. [url]https://pypi.org/project/pysrt/[/url]) to get the next subtitle text from the file while updating the ‘current_subtitle_index’. You can do your checking/matching logic in this function. You can also do your ‘random video selection from a folder’ logic and set various MovieTOP file parameter etc. in this function.By doing things like op("moviefilein1").par.file = insertRandomFileNameHere inside your python code.

You can then use a TimerCHOP with a CHOP Execute to call this function at intervals.

I don’t know how to do this without a heavy amount of python! Hope that is helpful!