Unable to save video by external signal without stoping the pipeline on a continuous stream

I am running a deepstream custom pipeline based on deepstream-test-3.py, on continuous USB camera stream input.
Based on external signals/events, I am controlling the state of the pipeline using the initial state as “NULL” then I am setting it to the “PLAYING” state. For saving the processed stream, I am setting the pipeline to a “PAUSED” state. But, it’s not saving the file using the filesink element as expected.
When we stop the stream by setting the state from “PLAYING” to “NULL”, I am getting the video saved. But to start the pipeline again and stop it every time, I am losing the stream information in the meantime the model and pipeline reload.