Before version 2.9.0, you could only write SPTS (Single Program Transport Stream) videos, now MPTS (Multiple Program Transport Stream) recording/streaming is available.
Common features
Using this feature, you can record MP4 and TS files with several videos in there. Furthermore, you can make any MPEG-TS based network streams (like UDP, DVB, SRT) with multiple programs.
The key property is "multiple-senders", as its value you should specify the number of your video sources.
MPlatform SDK
Here is an example on how to record two video files in one MP4 file:
// Conf source files
MFileClass file1 = new MFileClass();
file1.FileNameSet(source_path, "");
MFileClass file2 = new MFileClass();
file2.FileNameSet(source_path2, "");
// Conf writer
MWriterClass writer = new MWriterClass();
writer.PropsSet("multiple-senders", "2"); // "2" means two source files
// You can use different codecs and settings for different streams if you like:
string encoder = "format='mp4' video::codec='libopenh264' video::b='5M' video.1::codec='mpeg4' video.1::b='15M' audio::codec='aac' audio.1::codec='libmp3lame' program::program_num=80 program.1::program_num=90";
string file_path = "mpts_test.mp4";
// Start Writer twice
writer.WriterNameSet(file_path, encoder);
writer.ObjectStart(file1);
writer.ObjectStart(file2);
// Start source files
file1.FilePlayStart();
file2.FilePlayStart();
Of course, you can use three or more sources, just add more MFile objects and start the writer a few more times. Furthermore, if you change format to, for example, 'udp', this will create a network MPTS.
MFormats SDK
MPTS recording is similar to the MPlatform implementation. Of course, you should use MFReader objects instead of MFile and MFWriter instead of MWriter. Furthermore, it's necessary to set "channel_id" for each frame in the ReceiverFramePut method. For example:
// Conf source files
MFReaderClass reader1 = new MFReaderClass();
file.ReaderOpen(source_path, "");
MFReaderClass reader2 = new MFReaderClass();
file2.ReaderOpen(source_path, "");
// Conf writer
MFWriterClass writer = new MFWriterClass();
writer.PropsSet("multiple-senders", "2");
string encoder = "format='mpegts' video::codec='libopenh264' video::b='5M' video.1::codec='mpeg4' video.1::b='15M' audio::codec='aac' audio.1::codec='libmp3lame' program::program_num=80 program.1::program_num=90";
string file_path = "mpts_test.ts";
writer.WriterSet(file_path, 1, encoder);
...
// Working thread
reader1.SourceFrameGet(0, out MFFrame pFrame1, "");
reader2.SourceFrameGet(0, out MFFrame pFrame2, "");
writer.ReceiverFramePut(pFrame1, -1, "channel_id='0'");
writer.ReceiverFramePut(pFrame2, -1, "channel_id='1'");
Marshal.ReleaseComObject(pFrame1);
Marshal.ReleaseComObject(pFrame2);