Read caption text without decoding the video. The zip’s sample.ts carries Italian teletext on page 777, starting with “città” and “sera.”
dotnet add package RecursiveAI.OneMediaRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMedia; using RecursiveAI.OneMedia.Captions.Teletext; using var media = Media.Open("sample.ts"); var tracks = TeletextExtractor.ReadAll( media.Demuxer!); foreach (var track in tracks) foreach (var page in track.Subtitles) { var label = $"Page {page.Page} ({page.Language})"; Console.WriteLine(label); foreach (var cue in page.Document.Cues) Console.WriteLine(cue.Text); }
Unzip the example, then dotnet run.
Prints the page, language and caption text:
Page 777 (ita) città sera citéà sera циттш сера
The sample deliberately switches character sets, which is why the same caption appears as “citéà” and then “циттш.”
Full program
sample.ts is a generated stream, not a recording. Its Italian language tag stays the same while the sample switches character sets. To try a recording, replace sample.ts with an MPEG-TS file containing DVB teletext.
using RecursiveAI.OneMedia; using RecursiveAI.OneMedia.Captions.Teletext; using var media = Media.Open("sample.ts"); var tracks = TeletextExtractor.ReadAll(media.Demuxer!); if (tracks.Count == 0) Console.WriteLine("No teletext subtitle pages found."); foreach (var track in tracks) foreach (var page in track.Subtitles) { Console.WriteLine($"Page {page.Page} ({page.Language})"); foreach (var cue in page.Document.Cues) Console.WriteLine(cue.Text); }
dotnet run prints:
Page 777 (ita) città sera citéà sera циттш сера
If the extractor finds no subtitle pages, this program prints No teletext subtitle pages found.
Variations
Save page 777 as SRT
Replace everything after Media.Open with this. The filename includes the track index so two tracks carrying the same page don’t overwrite each other.
var options = new TeletextOptions { Pages = [new(7, 0x77)] }; var tracks = TeletextExtractor.ReadAll( media.Demuxer!, options); foreach (var track in tracks) foreach (var page in track.Subtitles) { var index = track.TrackIndex; string path = $"teletext-{index}-{page.Page}.srt"; Subtitles.Write(page.Document, path); Console.WriteLine(path); }
Prints teletext-0-777.srt. Choose a new output name before rerunning; Subtitles.Write won’t overwrite an existing file. The file starts with:
1 00:00:01,000 --> 00:00:03,000 città <font color="#ffff00">sera</font>
Related recipes
Read MPEG-TS programs and PIDs · Extract closed captions · Convert SRT to WebVTT
The short answer
Open the MPEG-TS file and pass its demuxer (the reader that separates its tracks) to TeletextExtractor.ReadAll. Each result groups the subtitle pages on one teletext track. Read page.Document.Cues for text and timing, or pass that document to Subtitles.Write to save it as SRT. OneMedia reads DVB teletext but does not write teletext back into the transport stream.
How do I extract subtitles from a .ts file?
Start by identifying the type of subtitles in the recording. DVB teletext carries characters and page controls. DVB bitmap subtitles carry images, and subtitles burned into the video are part of the picture. The teletext extractor handles the first case only. For a transport stream, OneMedia looks for a teletext descriptor in the program map table, which tells the reader which streams and services a program carries.
Use a fresh demuxer for caption extraction. ReadAll reads forward from the starting position and disables other tracks on that reader. Don’t first consume the packets to look for video and then expect to extract all the subtitles from the same position. Use this extractor rather than MediaFile.Subtitles: the latter doesn’t list teletext pages at this version. An empty result is not proof the file has no captions of any kind.
How do I select the right teletext subtitle page?
With no options, the extractor selects pages marked as subtitles in the page header or announced as subtitle pages by the transport stream. Look at the page number and advertised language in the results before choosing. To restrict the read, set TeletextOptions.Pages, as in the SRT variation: the first digit is the magazine number, and the other two are hexadecimal digits. Page 777 is magazine 7 and page number 0x77. If you don’t know the page and it wasn’t marked as a subtitle, AllPages can include ordinary teletext pages too.
A cue normally starts at the page’s transmission time and ends at the next transmission of that page. An empty transmission clears the previous text. Live subtitles sometimes repeat an expanding line as each word arrives; by default, OneMedia joins those updates into one cue with the completed text. If you need each update as it was transmitted, set TeletextOptions.Progressive to true.
SRT carries the text and cue times, not the full teletext page. Inspect page.Report when character mapping or visual fidelity matters. The teletext documentation lists what the cue model can’t represent, including mosaics and flashing text. Some characters have no mapping; for instance, Arabic letters can appear as the Unicode replacement character �.