Skip to main content

How do I play a video file with multiple video streams?


This tutorial will show you how to play a video file with several video streams using the TVFMediaPlayer class.

Many popular video formats, such as MKV, MP4, and others, can contain several video streams. You can use the Source_VideoStreamIndex property to set the video stream index for playback.

Sample code

// define the MediaPlayer object and create it
MediaPlayer1: TVFMediaPlayer;
MediaPlayer1 := TVFMediaPlayer.Create(Self);
// set the file name
MediaPlayer1.FilenameOrURL := 'video.mkv';

// enable audio playback (default DirectSound audio renderer will be used)
MediaPlayer1.Audio_Play := true;

// set the source mode to DirectShow. You can also use FFmpeg or VLC
MediaPlayer1.Source_Mode := SM_File_DS;

// set video stream index to 1 (index is zero-based)
MediaPlayer1.Source_VideoStreamIndex := 1;

// play the video file

You should set the Source_VideoStreamIndex property value before the Play method call.

Please get in touch with support to get help with this tutorial. Visit our GitHub page to get more code samples.