Open a source
Decoding of video files or streams in MPlatform SDK is operated by MFile object.
To open a source you should create an instance of the object and call FileNameSet method:
string pathToFile = @"c:\myVideo.mp4"; string extraProps = "video_track=-1"; MFileClass myFile = new MFileClass(); myFile.FileNameSet(pathToFile, extraProps);
where pathToFile is a path to a local file or a network stream URL, and extraProps is used to specify properties for the instance of an object. You can use many properties in this parameter. But working with IMProps interface and PropsSet method makes your code more clear.
You can use network links for playback, but note that live streams and protected videos (like some official video clips) can't be used for direct playback.
To generate direct links for opening Youtube videos (links like "https://www.youtube.com/watch?v=...") yt-dlp utility is used. Please note that this utility supports many sites (https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md). So, if you want to open, for example, Twitch or TikTok links, you should create a file named 'yt-dlp.list' in the "C:\Program Files (x86)\Medialooks\MPlatform SDK\Bin\x64\DecoderLib" folder and add each domain name (twitch.tv, tiktok.com) as a separate line in this file.
You can also choose the quality of the live stream: get the stream, look at the highest available number of the ts_programs with file::info::ts_programs property and then change the ts_program:
m_objFile.FileNameSet("https://cph-msl.akamaized.net/hls/live/2000341/test/master.m3u8", "ts_program=4");
Playback control
MFile object (and IMFile interface) has different methods to control playback:
myFile.FilePlayStart(); // to start playback myFile.FilePlayPause(10); // to pause playback for amount of time in seconds (use 0 to control pause duration manually) myFile.FileRateSet(2.0); // to make fast forward playback myFile.FileRateSet(-1.0); // to make reverse playback myFile.FilePlayStop(5.0); // to stop playback for amount of time in seconds (use 0 to control stop duration manually)
Playback with variable rate depends on rate value.
Fast forward playback up to x4 should be smooth - in this case, all the frames are decoded. For higher rates, some frames are skipped and MPlatform just seeks to the next target frame.
You can increase this limit by setting "file.max_forward_rate" property for the MFile object or in system registry:
HKEY_CURRENT_USER\SOFTWARE\Medialooks\MPlatform\MFile file.max_forward_rate = 4.0
The same is valid for reverse playback with "file.max_reverse_rate":
HKEY_CURRENT_USER\SOFTWARE\Medialooks\MPlatform\MFile file.max_reverse_rate = 2.0
Note that higher values lead to higher CPU usage for pre-decoding of frames for smooth playback. So too high values may not have an effect.
About slow playback (with a rate lower 1.0), MPlatform plays source frame by frame with no smooth correction for video.
For any rate value, there is a correction for audio - it is adapted to the rate by default. You can change this audio behavior by setting "audio.variable_rate" property:
HKEY_CURRENT_USER\SOFTWARE\Medialooks\MPlatform\MFile audio.variable_rate = true
Marking in and out points
You can cut unnecessary parts of video by specifying in- and out-points with FileInOutSet method in seconds or with FileInOutSetTC method in timecodes. For example:
M_TIMECODE inTC = new M_TIMECODE(); inTC.nHours = 1; inTC.nMinutes = 12; inTC.nSeconds = 34; inTC.nFrames = 56; M_TIMECODE outTC = new M_TIMECODE(); outTC.nHours = 1; outTC.nMinutes = 25; outTC.nSeconds = 15; outTC.nFrames = 27; myFile.FileInOutSetTC(ref inTC, ref outTC);
or
double inPoint = 12.5; double outPoint = 24.5; myFile.FileInOutSet(inPoint, outPoint);
You can specify in- and out- points in FileNameSet method in extra properties. To specify in seconds you should call something like:
myFile.FileNameSet(pathToFile, "in=12.5 out=24.5");
And in case of timecode is used you should use "tc_in" and "tc_out" properties specified in "HH:MM:SS:FF" format like:
myFile.FileNameSet(pathToFile, "tc_in=01:12:34:56 tc_out=01:25:15:27");
Seeking
To jump to the specified position of the current file you should use FilePosSet method:
m_objFile.FilePosSet(dblPos, 0);
This method contains additional preroll parameter that uses when seeking accuracy is not enough. Preroll makes seeking more accurate but the operation takes more time then. The greater preroll value the longer seeking is.
The position is in seconds and it is calculated from the in-point of the file.
FilePosSetTC method does actually the same but its position is in timecode format for frame-accurate seeking.