Deepstream Test3 output save

Hello, Hope you are doing well.
I am doing testing using python-binding code using deepstream-test. I want to save the output in the form of the video. I am not be able to save the output of the input video. Can you guide me how I can save the output of the input stream.
I am using the following code


You may refer to c++ code
for how to encode to file, make customization accordingly to python version.