Displaying Subtitles

Introduction

LEADTOOLS supports the timed delivery of subtitles from certain demultiplexers.

Subtitle delivery is only possible in a graph that has a clock, such as a play graph.

The application is responsible for the actual display mechanism. This can be accomplished with a filter, such as the LEAD Video Text Overlay Filter, or with a mechanism external to the graph.

Supported Demultiplexers

Currently, the LEAD MKV demultiplexer is the only demultiplexer that can display subtitles.

Checking for Support

In order to determine if a demultiplexer can display subtitles, call the ILMDmxSubtitle interface from the demultiplexer in the play graph. See the following code examples.

C++ Example

// find the playback demultiplexer 
CComPtr<IUnknown> splitter; 
m_player->GetSubObject(ltmmPlay_Object_Splitter, &splitter); 
if(splitter) 
{ 
   // query IServiceProvider 
   CComQIPtr<IServiceProvider> sp = splitter; 
   if(sp) 
   { 
      // check if the demultiplexer subtitle service is available 
      sp->QueryService(__uuidof(LMDmxSubtitle), __uuidof(ILMDmxSubtitle), (void**) &m_subtitle); 
      if(m_subtitle) 
      { 
         // determine if there are any subtitle tracks 
         CComPtr<ILMSubtitleTrackList> tracks; 
         m_subtitle->get_Tracks(&tracks); 
         long count; 
         tracks->get_Count(&count); 
         if(count > 0) 
         { 
            // set the application callback interface to receive subtitle notifications 
            m_subtitle->putref_Callback((ILMDmxSubtitleCallback*) this); 
         } 
      } 
   } 
} 

C# Example

try 
{ 
   // find the playback demultiplexer service provider 
   IServiceProvider sp = (IServiceProvider) player.GetSubObject(PlayObject.Splitter); 
   if (sp != null) 
   { 
      // check if the demultiplexer subtitle service is available 
      subtitle = (LMSubtitleLib.LMDmxSubtitle)sp.GetService(typeof(LMSubtitleLib.LMDmxSubtitle)); 
      if (subtitle != null && subtitle.TextTracks.Count > 0) 
      { 
         // set the application callback interface to receive subtitle notifications 
         subtitle.Callback = this; 
      } 
   } 
} 
catch 
{ 
 
} 

VB.NET Example

Try 
   ' find the playback demultiplexer service provider 
   Dim sp As IServiceProvider = DirectCast(player.GetSubObject(PlayObject.Splitter), IServiceProvider) 
   If sp IsNot Nothing Then 
      ' check if the demultiplexer subtitle service is available 
      subtitle = DirectCast(sp.GetService(GetType(LMSubtitleLib.LMDmxSubtitle)), LMSubtitleLib.LMDmxSubtitle) 
      If subtitle IsNot Nothing AndAlso subtitle.TextTracks.Count > 0 Then 
         ' set the application callback interface to receive subtitle notifications 
         subtitle.Callback = Me 
      End If 
   End If 
Catch 
End Try 

Enumerating and Selecting Subtitles

The subtitles contained in the source video are exposed through the ILMDmxSubtitle.Tracks list. For convenience, the ILMDmxSubtitle interface also exposes the ILMDmxSubtitle.TextTracks list, but only to enumerate subtitle text tracks. Enumerate individual tracks using the ILMSubtitleTrackList interface. Information about each track is exposed through the ILMSubtitleTrack interface.

A track must be selected in order to receive notifications. By default, no tracks are selected. Call the ILMDmxSubtitle.SelectTrack method to select tracks. The currently selected tracks are exposed through the ILMDmxSubtitle.SelectedTracks list. Tracks can be selected and deselected at any time.

Implementing the ILMDmxSubtitleCallback

To receive subtitle cue notifications, an application calls the ILMDmxSubtitleCallback.Cue method. Perform the following steps to implement the ILMDmxSubtitleCallback.Cue method:

  1. Implement the ILMDmxSubtitleCallback interface.
  2. Assign the interface pointer to the ILMDmxSubtitle.Callback property.

The demultiplexer will call the application's implementation of the ILMDmxSubtitleCallback.Cue method when a cue needs to be displayed or hidden.

Help Version 20.0.2019.9.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Filters C API Help