The Video SDK (MFormats SDK and MPlatform SDK) can show subtitles of a transport stream, insert subtitles into MPEG-TS and HLS output from subtitle files or while the stream is running, and write WebVTT for HLS. This article is the map: it shows which article describes which task, what the output subtitle types are and which samples to start with.
What do you want to do
| Task | Article |
|---|---|
| Show the DVB subtitles or the DVB Teletext of a TS file, a DVB or a UDP stream | Displaying DVB subtitles/teletext from transport stream |
| Add subtitles from ASS or SRT files to the output as DVB subtitles or DVB Teletext | How to Insert ASS and SRT Subtitles as DVB, DVB Teletext |
| Insert subtitles while the stream is running (live text, operator, speech recognition) | How to Insert DVB Subtitles and DVB Teletext On the Fly During Live Output |
| Write subtitles to an HLS stream as WebVTT | WebVTT subtitles for HLS |
Output subtitle types
| Writer codec | Kind | Output |
|---|---|---|
subtitle::codec='dvbsub' |
Bitmap DVB subtitles | MPEG-TS (format='mpegts'): a file, UDP or SRT |
subtitle::codec='dvbtxt' |
DVB Teletext (text) | MPEG-TS (format='mpegts'): a file, UDP or SRT |
subtitle::codec='webvtt' |
WebVTT (text) | HLS (format='hls') |
One output can have several subtitle tracks, for example a DVB Teletext track and a bitmap DVB subtitle track. The tracks of the writer are written with the prefixes subtitle::, subtitle.1::, subtitle.2:: and so on.
The stream ID connects the parts
Whatever the source of the subtitles is, a subtitle track is always connected to the writer by its stream ID: external_subtitle.stream_id of the reader (subtitle files) or the field stream_id of the subtitle_json (live subtitles) has to be the same as subtitle::stream_id of the writer track. The most common reason for an output without subtitles is that the numbers are different.
Samples
Two samples come with the SDK. Both exist for the MFormats SDK and for the MPlatform SDK, both write MPEG-TS to a file, UDP or SRT, and both let you edit the subtitles and their style.
| Subtitle Conversion Sample | Subtitle Generation Sample | |
|---|---|---|
| Subtitles from | ASS and SRT files (and the editor of the sample) | The same, and the Live Subtitle Editor: the subtitles are created while the output runs |
| Source | A file or a playlist | A file, a capture device, a network URL or an external source |
| Shows | The reader and the writer configuration of the subtitle tracks (external_subtitle, subtitle::...) |
The same, and the subtitle_json frame property and the escaping of the text |
| Article | How to Insert ASS and SRT Subtitles as DVB, DVB Teletext | How to Insert DVB Subtitles and DVB Teletext On the Fly During Live Output |
| MFormats SDK folder | Samples\C#\Sample Subtitle Conversion |
Samples\C#\Sample Subtitle Generation |
| MPlatform SDK folder | Samples Basic\C#\Subtitle Conversion Sample |
Samples Basic\C#\Subtitle Generation Sample |
The folders are relative to the installation folder of the SDK (C:\Program Files (x86)\Medialooks\MFormats SDK or ...\MPlatform SDK). They replace the Subtitle Insertion Sample of the earlier SDK versions.
Requirements
- The output is an MPEG transport stream (
format='mpegts', a file, UDP or SRT) for DVB subtitles and DVB Teletext, and HLS (format='hls') for WebVTT. - Inserting live subtitles with the frame property
subtitle_jsonneeds a 64-bit application. - The writer examples use the
libopenh264video codec and theaacaudio codec; any other codec supported by the writer can be used. - Subtitle insertion may require the Closed Caption plugin license.
Properties at a glance
The most used properties. The details, the values and the examples are in the articles.
| Where | Property | What it does | Article |
|---|---|---|---|
Reader (MFile, MFReader) |
file::info::subtitle_tracks, file::info::subtitle.N::*
|
The number of the subtitle tracks of the source and the information about each of them | Displaying subtitles |
| Reader | file::subtitle_track |
The subtitle track that is shown | Displaying subtitles |
| Reader |
teletext_page, teletext.force_ffmpeg
|
The Teletext subtitle page of the source and the FFmpeg Teletext path | Displaying subtitles |
| Reader |
external_subtitle, external_subtitle.stream_id (and .N) |
Attach an ASS or SRT file as a subtitle track and give it a stream ID | ASS and SRT insertion |
| Reader | experimental.out_subtitle_packets |
Pass the subtitle packets to the writer (2) instead of drawing them on the picture |
ASS and SRT insertion |
| Frame |
subtitle_json (and subtitle_json.N) |
A live subtitle event as JSON, attached to a frame with MFStrSet
|
Live insertion |
Writer (MWriter, MFWriter) |
subtitle::codec |
dvbsub, dvbtxt or webvtt
|
ASS and SRT insertion |
| Writer |
subtitle::stream_id, subtitle::pid, subtitle::metadata::language
|
The stream ID that connects the track with its source, the PID in the transport stream and the language | ASS and SRT insertion |
| Writer |
subtitle::font, subtitle::font_size, subtitle::outline and others |
The formatting of the subtitle text | ASS and SRT insertion |
| Writer |
subtitle::page_number, subtitle::teletext_*, subtitle::data_identifier
|
The Teletext page, the character sets, the rows and the data identifier | ASS and SRT insertion |
| Writer |
subtitle::subtitling_type, subtitle::default_font, subtitle::canvas_*
|
The settings of the bitmap DVB subtitles | ASS and SRT insertion |
Every subtitle track has a number. The first track uses the property names as above, the next ones use the index in the name: external_subtitle.1, subtitle.1::codec, subtitle_json.1.
Articles
Still have questions?
Tell us what didn’t work or what you’d like clarified.