Dynamic on-screen display while the pipeline is running

I do not want the output stream to be displayed throughout the runtime of the application. I just want to display the stream when I have some particular conditions met.

could you check this topic https://devtalk.nvidia.com/default/topic/1068104/deepstream-sdk/how-to-dynamically-add-remove-filesink/post/5413713/#5413713

you can add probe to the sink pad of the osd element, when the condition not met, just return, you can refer test1 app code:
static GstPadProbeReturn
osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)