New approach
Since the 2.2.1 version, you can encode to more than 2 destinations at the same time using a single encoder instance.
For this, you can specify the encoding configuration like
format='mp4' stream.1::format='mp4' stream.2::format='mp4' video::codec='libopenh264'
audio::codec='aac' stream.1::path='C:\test1.mp4' stream.2::path='C:\test2.mp4'You should set "stream.idx::format" to set a target format, and "stream.idx::path" to set the target destination. It works both for local files encoding and network streaming.
Note please that this feature is available only for MPlatform SDK and for the Ultimate Edition of MFormats SDK.
Switching a file segment without interrupting other outputs
When a Writer has several output destinations, you can switch only selected destinations to a new file segment. This lets file recording continue in a new file while network outputs remain connected and keep streaming.
Pass the following parameters to WriterNameSet for MWriter or WriterSet for MFWriter:
- seamless_switch='true' enables seamless switching.
- seamless_switches='[INDEXES]' specifies the zero-based indexes of the outputs that must be switched to the new segment.
The main Writer destination has index 0; additional destinations configured as stream.1, stream.2, and so on have indexes 1, 2, and so on.
Include only the outputs that must start a new segment in seamless_switches. Do not include network outputs that must continue streaming.
For example, configure the main output as an MP4 file and stream.1 as a UDP stream:
format='mp4' video::codec='libopenh264' audio::codec='aac' stream.1::format='mpegts' stream.1::path='udp://127.0.0.1:4150'To start recording the next MP4 segment, switch only output 0:
writer.WriterNameSet(
@"C:\\Recordings\\segment_2.mp4",
"seamless_switch='true' seamless_switches='0'");In this example, only the local MP4 muxer is switched to the new file. The UDP output (stream.1) continues without being restarted or requiring clients to reconnect.
Legacy approach
For compatibility with older applications, MWriter and MFWriter also support the second_encoder attribute. Use the stream.idx approach above for new integrations because it supports more than two destinations.
Specify both the destination and its container format:
second_encoder='[YOUR_TARGET_PATH_OR_URL]' second_encoder::format='[TARGET_CONTAINER]'For example, simultaneous UDP streaming and MP4 file capturing can be configured as follows:
format='mp4' video::codec='n264' audio::codec='aac' second_encoder='udp://127.0.0.1:3041' second_encoder::format='mpegts'