Latency with mjpg
Hi,
I want to calibrate my Ip cam using calibration sample but I have got some latency 1 s when I run program and when I start calibration sometime 10s (ten seconds!).
I have write this small program and try to understand what happen :
Mat view0;
for(i = 0;i<tps.size();i++)
{
if( capture.isOpened() )
{
tps[i] = getTickCount();
while (!capture.grab());
capture.retrieve(view0);
//view0.copyTo(view);
}
}
for(i = 1;i<tps.size();i++)
{
cout << (tps[i] - tps[i-1])/getTickFrequency() << "\n";
}
and it gives me these results : 22 values like 0.04s (first images) and after 0.852972s and many values like 0.5s (when buffer is empty?)
I understand that MJPG is a flow and you have to read all flow to have last image. Is it right?
Is it possible to flush flow before reading?
Now I have got a switch so my network is clean. i have a record a small video where we can see
- using mozilla to display my IPcam (upper left) bottom left opencv
- using opencv my ipcam (bottom left)
- a wab cam (Logitech 270) upper right
As you can see latency for each link are different. It seems that opencv with ffmpeg has got greater latency time than mozilla and webcam (for webcam it is logical).
have you got same latency time?
Thanks for yours answers
Not sure to understand fully the problem. The latency occurs when you try to retrieve online the IP camera stream or when you try to read a MJPEG video file ?
I think that it is the first case. Anyway when I try to read a MJPEG video file (no display or waitKey, with the overloaded >> operator), I got:
The video:
I may be wrong but I don't think that the latency comes from the video codec but rather from some network latency or camera fps maybe ?
Thanks for your answer.
It's an IP cam smartCam HDPro samsung (http://user:[email protected]/cgi-b...) with a resolution 1280x960 for this adress.
I wondering : At time t I use capture>> frame1 and after do some processing. (0.5s later for example) I do a new capture>> frame2
If real time for frame1 is t what is real time for frame2? Is it t+1/25s (for fps 25) or is it t+0.5s?
For network I am waiting for switch to have my private network and test latency.
with ffplay I have got this :
just saying,
getTickCount()
measures cpu time only, not wall time.so, your counting does neiter include io or sleep, blocking sockets or the like.
to measure network latency, you need realtime clock, e.g. from std::chrono