Overview
You can display DVB subtitles and DVB Teletext subtitles from a transport stream source, such as a TS file, DVB stream, UDP stream, or another supported MPEG-TS input, by using MPlatform SDK or MFormats SDK.
The general workflow is:
- Open the source with
MFilein MPlatform SDK orMFReaderin MFormats SDK. - Check how many subtitle tracks are available.
- Get detailed information about the subtitle tracks, if needed.
- Select the subtitle track to display.
- For DVB Teletext subtitles, configure the Teletext page and FFmpeg Teletext reader options when required.
- Start playback or frame processing.
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. Check if subtitle tracks are available
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. Get subtitle track information
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 subtitle 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. DVB Teletext subtitle specifics
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.
Use teletext_page to select the Teletext subtitle page:
file.PropsSet("teletext_page", "888");For MFormats SDK:
reader.PropsSet("teletext_page", "888");If the Teletext subtitles are not detected or decoded by the default reader path, enable the FFmpeg Teletext path with teletext.force_ffmpeg.
Runtime properties
file.PropsSet("teletext.force_ffmpeg", "true");
file.PropsSet("teletext_page", "888");For MFormats SDK:
reader.PropsSet("teletext.force_ffmpeg", "true");
reader.PropsSet("teletext_page", "888");These options can also be stored in the registry for the reader component.
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.