Is it possible to read .srt or other subtitle files with OF?

Maybe with an addon and timed with a video (like a normal video player would do)?
Thank you.

Hi,
did you try this one?

It is quite old but should work, maybe with some tweaking.
you can find a lot of addons in ofxaddons.com, there I found this one.

1 Like

@roymacdonad thank you. Yeah, it seems I used the wrong search terms (.srt ofxAddon Open Frameworks)…

I find it easier to visit ofxaddons.com rather than doing a google search. Note that ofxaddons does not have a search feature, so I just use the browsers “find in page” command.
best

1 Like

I tried YCAMInterlab/ofxSubtitles, it works on desktop, but not with Emscripten (the subtitles get dumped all at once). I found this one, which looks promising: https://github.com/saurabhshri/simple-yet-powerful-srt-subtitle-parser-cpp
And I wonder, if it would be difficult to use it with OF?

The link above (simple-yet-powerful-srt-subtitle-parser-cpp) does work with OF.
It is no problem to jump to a movie position from a corresponding subtitle.
I wonder if it is also possible to call the right subtitle if the movie reached a certain position?
Do I have to iterate through each subtitle and check the start and end time to find the current one?
Something like that maybe (Edit: Yes, it works like that, not sure if it is efficient)?

	for (SubtitleItem* element : sub)
	{
		if (element->getStartTime() <= movieTime && element->getEndTime() >= movieTime) {
			ofDrawBitmapString(element->getDialogue(), 75, 500);
		}
	}

This is how I implemented the example in OF:


#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	SubtitleParserFactory* subParserFactory = new SubtitleParserFactory("example.srt");
	SubtitleParser* parser = subParserFactory->getParser();

	//to get subtitles

	std::vector<SubtitleItem*> sub = parser->getSubtitles();

	for (SubtitleItem* element : sub)
	{
		cout << "BEGIN" << endl;
		cout << "startString : " << element->getStartTimeString() << endl;
		cout << "start : " << element->getStartTime() << endl;
		cout << "endString : " << element->getEndTimeString() << endl;
		cout << "end : " << element->getEndTime() << endl;
		cout << "text : " << element->getText() << endl;
		cout << "justDialogue : " << element->getDialogue() << endl;
		cout << "words count : " << element->getWordCount() << endl;
		cout << "words :";
		std::vector<std::string> word = element->getIndividualWords();
		for (std::string display : word)
			cout << display << ", ";
		cout << endl;

		cout << "speakerCount : " << element->getSpeakerCount() << endl;
		cout << "speakers : ";
		if (element->getSpeakerCount())
		{
			std::vector<std::string> name = element->getSpeakerNames();
			for (std::string display : name)
				cout << display << ", ";
			cout << endl;
		}

		cout << "ignore : " << element->getIgnoreStatus() << endl;
		cout << "END" << endl << endl;
	}
}

I made a minimal subtitle displaying example: https://github.com/Jonathhhan/ofEmscriptenExamples/tree/main/subtitleExample

2 Likes