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 YouTube links for playback, but note please that live streams and protected videos (like some official video clips) can't be used for direct playback.
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);
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");
To jump to the specified position of the current file you should use FilePosSet method:
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.