File is not getting saved properly

• Hardware Platform: dGPU
• DeepStream Version: 5.0
• TensorRT Version: 7.0.0-1+cuda10.2
• NVIDIA GPU Driver Version: 465.19.01

Hello,
I have created a script to dynamically attach and detach elements in the pipeline to store the video, it works and saves 2-3 consecutive videos but fails after that, I am getting the following error,

0:01:23.693699417 969453 0x7f549c002b00 WARN default v4l2-utils.c:189:gst_v4l2_error: error: Device ‘/dev/nvhost-msenc’ failed during initialization

0:01:23.693707872 969453 0x7f549c002b00 WARN default v4l2-utils.c:192:gst_v4l2_error: error: Call to S_FMT failed for YM12 @ 1080x580: Unknown error -1

0:01:23.693725783 969453 0x7f549c002b00 WARN videoencoder gstvideoencoder.c:685:gst_video_encoder_setcaps: rejected caps video/x-raw(memory:NVMM), width=(int)1080, height=(int)580, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, framerate=(fraction)25/1, batch-size=(int)1, num-surfaces-per-frame=(int)1, format=(string)I420

I am not sure if its related v4l2 driver or nvv4l2h264enc issue…

Can you upgrade to latest deepstream version 5.1?

How can we reproduce you failure? Which app are you using?

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.