Saving frame with detected object [Jetson Nano, DS4.0.2]

Good morning everyone,

I am working on a Jetson Nano with Deepstream 4.0.2.
I have modified deepstream-test3 sample app to add apache kafka messages whenever an object is detected in one of the input streams. This is now the pipeline: (please forget the apostrophes)

nvstreammux -> nvinfer -> nvtiler -> nvvidconv -> nvosd -> tee
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ | -> video-renderer
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’ |-> msgconv -> msgbroker

What I am trying to achieve now is to save in .jpg file each frame that has been detected to contain at least one object.
Thus, I have multiple streams as input, I have a rendered video ouput, I have a kafka message for each stream anytime an object is detected, I would like to add the storing of each frame that has nvinfer has detected to include at least one object.

Would you be so kind to give me some hints?
(I have found the following post: How to crop the image and save , but I am not really able to understand how to integrate that example in my pipeline, nor to understand if that is the easiest way to follow).

I thank you very much in advance for the support!
Best regards

If you would like to crop the objects and save them into JPEGs, you can check

If you would like to save full frames, you can check