Skip to main content

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

Introduction

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
var
MediaPlayer1: TVFMediaPlayer;
begin
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
MediaPlayer1.Play();
end;

You should set the Source_VideoStreamIndex property value before the Play method call. The Source_VideoStreamIndex property is zero-based, so the first video stream has an index of 0.

Most of the file formats, like MP4, MKV, and others, are supported.


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