Overview
Use this workflow to display or verify a subtitle track already carried by an MPEG transport stream. Open a TS file or a supported network source, list its subtitle tracks, and select the one to display.
To check the output of the Conversion or Generation sample, open the resulting stream at the receiver. Check the expected track and language, then play through a known cue and verify the text appears. For Teletext, select the page used by the sender if automatic selection does not find it.
Supported subtitle types
The SDK can display subtitle tracks available in the source transport stream, including:
- DVB subtitles — bitmap-based subtitles.
-
DVB Teletext subtitles — Teletext subtitle pages, commonly page
888.
The available subtitle tracks and their metadata can be inspected through source information properties.
1. Open the source
In MPlatform SDK, use MFile.
MFileClass file = new MFileClass();
file.FileNameSet(sourcePath, "");In MFormats SDK, use MFReader.
MFReaderClass reader = new MFReaderClass();
reader.ReaderOpen(sourcePath, "");2. Count subtitle tracks
To check whether the source contains subtitle tracks, read the file::info::subtitle_tracks property with PropsGet.
MPlatform SDK
string tracksNumber = "";
file.PropsGet("file::info::subtitle_tracks", out tracksNumber);
Console.WriteLine($"Subtitle tracks: {tracksNumber}");MFormats SDK
string tracksNumber = "";
reader.PropsGet("file::info::subtitle_tracks", out tracksNumber);
Console.WriteLine($"Subtitle tracks: {tracksNumber}");If the returned value is 0 or empty, the source does not expose subtitle tracks through this property.
3. Inspect subtitle track metadata
Each subtitle track can expose additional information through indexed properties. Track indexes are zero-based.
For example, to get the codec name for subtitle track 0:
string subtitleCodecName = "";
file.PropsGet("file::info::subtitle.0::codec_name", out subtitleCodecName);
Console.WriteLine($"Subtitle codec: {subtitleCodecName}");The same property can be used with MFReader in MFormats SDK:
string subtitleCodecName = "";
reader.PropsGet("file::info::subtitle.0::codec_name", out subtitleCodecName);
Console.WriteLine($"Subtitle codec: {subtitleCodecName}");Common subtitle information properties are:
-
file::info::subtitle.0::idx— subtitle stream index. -
file::info::subtitle.0::codec_name— subtitle codec name. -
file::info::subtitle.0::time_base— subtitle time base. -
file::info::subtitle.0::start_time— subtitle start time. -
file::info::subtitle.0::duration— subtitle duration.
Replace 0 with the required subtitle track number to inspect other subtitle tracks. For example:
file::info::subtitle.1::codec_name
file::info::subtitle.2::codec_name4. Select the track to display
To display subtitles, set the subtitle track index with file::subtitle_track.
For example, to select subtitle track 0:
MPlatform SDK
file.PropsSet("file::subtitle_track", "0");MFormats SDK
reader.PropsSet("file::subtitle_track", "0");After the track is selected, start playback or frame processing as usual. The selected subtitle track is rendered together with the video output.
5. Select a Teletext page if needed
DVB Teletext subtitles may require additional Teletext options. In many broadcasts, Teletext subtitles are stored on page 888, but the actual page can be different depending on the source.
So use teletext_page property to select the Teletext subtitle page. If the Teletext subtitles are not detected or decoded by the default reader path, enable the FFmpeg Teletext path with teletext.force_ffmpeg property:
file.PropsSet("teletext_page", "888");
file.PropsSet("teletext.force_ffmpeg", "true");These options can also be stored in the registry for the reader component. For example, MFormats registry options:
Computer\HKEY_CURRENT_USER\SOFTWARE\Medialooks\MFormats\MFReader
teletext.force_ffmpeg = true
teletext_page = 888If these registry values do not exist, create them manually. The default Teletext subtitle page is usually 888, but you should use the page number required by the source stream.
MPlatform example
The following example opens a transport stream source, checks available subtitle tracks, selects the first subtitle track, and starts playback.
using System;
using System.Runtime.InteropServices;
using MPLATFORMLib;
public static class DvbSubtitlePlaybackMPlatform
{
public static void PlayWithSubtitles(string sourcePath)
{
MFileClass file = null;
try
{
file = new MFileClass();
file.FileNameSet(sourcePath, "");
string tracksNumber = "";
file.PropsGet("file::info::subtitle_tracks", out tracksNumber);
Console.WriteLine($"Subtitle tracks: {tracksNumber}");
string subtitleCodecName = "";
file.PropsGet("file::info::subtitle.0::codec_name", out subtitleCodecName);
Console.WriteLine($"Subtitle track 0 codec: {subtitleCodecName}");
file.PropsSet("file::subtitle_track", "0");
// Use these options for DVB Teletext subtitles when needed.
file.PropsSet("teletext.force_ffmpeg", "true");
file.PropsSet("teletext_page", "888");
file.FilePlayStart();
// Keep the application running while playback is active.
}
finally
{
if (file != null)
Marshal.ReleaseComObject(file);
}
}
}MFormats example
The following example opens a transport stream source, checks available subtitle tracks, selects the first subtitle track, and reads frames.
using System;
using System.Runtime.InteropServices;
using MFORMATSLib;
public static class DvbSubtitlePlaybackMFormats
{
public static void ReadFramesWithSubtitles(string sourcePath)
{
MFReaderClass reader = null;
try
{
reader = new MFReaderClass();
reader.ReaderOpen(sourcePath, "");
string tracksNumber = "";
reader.PropsGet("file::info::subtitle_tracks", out tracksNumber);
Console.WriteLine($"Subtitle tracks: {tracksNumber}");
string subtitleCodecName = "";
reader.PropsGet("file::info::subtitle.0::codec_name", out subtitleCodecName);
Console.WriteLine($"Subtitle track 0 codec: {subtitleCodecName}");
reader.PropsSet("file::subtitle_track", "0");
// Use these options for DVB Teletext subtitles when needed.
reader.PropsSet("teletext.force_ffmpeg", "true");
reader.PropsSet("teletext_page", "888");
while (true)
{
MFFrame frame = null;
try
{
((IMFSource)reader).SourceFrameGet(-1, out frame, "");
if (frame == null)
break;
// Process or preview the frame here.
}
finally
{
if (frame != null)
Marshal.ReleaseComObject(frame);
}
}
reader.ReaderClose();
}
finally
{
if (reader != null)
Marshal.ReleaseComObject(reader);
}
}
}Notes
- Use
file::info::subtitle_tracksto check how many subtitle tracks are available. - Use
file::info::subtitle.N::codec_nameand related properties to inspect a specific subtitle track. - Use
file::subtitle_trackto select the subtitle track to display. - For DVB Teletext subtitles, use
teletext_pageto select the required page. - If Teletext subtitles are not detected by the default reader path, use
teletext.force_ffmpeg=true. - Page
888is a common Teletext subtitle page, but the correct page depends on the source stream.
Reading and writing subtitles
This article is about reading subtitles of a transport stream. The properties file::subtitle_track, teletext_page and teletext.force_ffmpeg belong to the reader. To write subtitles into a transport stream, the writer properties subtitle::codec, subtitle::stream_id and, for DVB Teletext, subtitle::page_number are used, see Insert ASS or SRT subtitles into MPEG-TS and Insert DVB subtitles or DVB Teletext during live output. When you read back a stream that was written with subtitle::page_number, use the same page number for teletext_page.
See also
Still have questions?
Tell us what didn’t work or what you’d like clarified.