RTSP with VideoCapturing() makes 3 second delay

Hikvision Ip camera RTSP with VideoCapturing() makes 3 second delay

I am trying to make a real time detection on the Ip camera and I am facing a three second delay on the deployment
I want to minimize this delay as much as possible

for now I am using Flask to connect HTML files and python code (my interface present the video by sending frame by frame to the interface)
even without using the model and without prediction there is delay for the displaying only on the interface

Actually, I have done two experiments (display the video on the interface by sending frame by frame with flask without predictions)

  1. I tried to run the code on Vs code using SSH on remote machine which I am using and there was a delay for around 3 seconds when displaying on the interface (even without the model inference) and when I check
    success, frame = camera.read()
    print("the seconds after first read== ", time.time()-st)
    to see the first read how many time does it takes it was

and after first reading it was less

  1. I tried to run the code on my own device and there were a little delay for less than a second which I see it acceptable delay
    and comparing the experiments for checking the time
    there was no 2 seconds delay on first reading as in experiment 1

For now I need to always run the code on the remote machine so what is the reason of this delay ???

initializing a device takes time. this can also affect the first read.

and this is the reason of the delay?

how to solve this problem of initializing device to take less time?
the same code in other devices is much faster why it happens?