There is a "second_encoder" attribute for encoding configuration of MWriter and MFWriter objects.
You should specify
second_encoder='[YOUR_TARGET_PATH_OR_URL]'
second_encoder::format='[TARGET_CONTAINER]'
Here is an example of simultaneous UDP streaming and MP4 file capturing:
format='mp4' video::codec='n264' audio::codec='aac' second_encoder='udp://127.0.0.1:3041' second_encoder::format='mpegts'
In this case, video and audio settings are the same. The difference is only in the destination.