Hello mzamanov , I would just create a new file and start writing to it instead of the different one. One note here is that it would work with MJPEG, but for h264/h265 encoding, you would need to wait for a keyframe, otherwise, you would just have some strange artifacts at the beginning. You can reduce this effect by setting keyframes more frequently, but this would also increase the final file size.
Thanks, Erik