File is not getting saved properly

Unfortunately, I need to deploy this code on Jetpack4.4 so need to stuck to DS5.1 for a time being, I am basically attaching a a video elements in the pipeline through a tee element and then unlinking and removing those elements from the pipeline after every 10 sec of video. As per my understanding these stored files remain open even after the unlinking and there is some limit ie. 16 [mmapi] libv4l2: error attempting to open more then 16 video devices, I can make it 32 or more and install v4l2 again but I need a way to properly close those files so that I can add any number videos into it.