Extract Teletext Subtitles to SRT with FFmpeg
Broadcast MPEG Transport Stream (.ts) files frequently embed subtitles within DVB teletext data tracks rather than standard text formats. This guide outlines how to inspect an incoming TS file, select the correct teletext page or stream, and decode the embedded broadcast captions into a standard SubRip (.srt) file using simple FFmpeg commands.
Step 1: Identify the Subtitle Stream
Before extracting, analyze the TS container to locate the stream index and check the teletext composition. Run the following command in your terminal:
ffmpeg -i input.tsIn the output, look under the stream mappings for a subtitle line similar to:
Stream #0:2[0x234]: Subtitle: dvb_teletext ([p][g][c][e] / 0x65636770)
Take note of the stream index (for example, 0:2 or
subtitle stream 0:s:0).
Step 2: Extract and Convert Using Stream Mapping
If the transport stream contains a single subtitle channel, you can map the subtitle track directly and convert the codec to SRT:
ffmpeg -fix_sub_duration -i input.ts -map 0:s:0 -c:s srt output.srt-fix_sub_duration: Resolves common broadcast issues where subtitle display intervals are not cleanly defined, preventing text from lingering on screen.-map 0:s:0: Selects the first available subtitle stream.-c:s srt: Specifies the SubRip subtitle encoder.
Step 3: Extracting by Teletext Page Number
Teletext services often carry multiple pages (such as page 888 for deaf and hard-of-hearing subtitles, or page 777 for alternate languages) within the same stream. If extracting by stream index yields empty files or mixed text, specify the exact teletext page before declaring the input:
ffmpeg -fix_sub_duration -txt_page 888 -i input.ts -map 0:s:0 -c:s srt output.srt-txt_page <number>: Tells the teletext decoder to filter and decode only the lines matching the designated 3-digit page number.
Step 4: Handling Multiple Subtitle Streams
If the TS stream carries multiple languages on separate teletext
streams, inspect the stream metadata from Step 1 and adjust the
-map parameter accordingly:
ffmpeg -fix_sub_duration -txt_page 888 -i input.ts -map 0:3 -c:s srt subtitles_eng.srtReplace 0:3 with the exact stream identifier shown in
your file's probe data.