I’m sitting on a laptop on my LAN right now. I open a new tab and click my bookmark to my default lovelace view that has 1 stream on it (preloaded). The page takes less than a second to load and then the stream goes live in less than a second after that. I think my substream is at 6fps, and it looks like its not too much worse than that in my browser. Definitely better than 1fps.
I just don’t know how any of this works below the surface otherwise i may be able to help you understand why my results are different than yours. If it helps, i’m running HA on a pi4 w/ 4gb ram. Very few add-ons, and my typical resting CPU load is around 4 or 5%.
Oh, and my little test up there is on an old macbook air, like 2011 or 2012 i5 w/ 4gb ram.
I really appreciate all the help. At this point, I think it must be on the camera side… Is there any way you could log into your camera and send me the config of the following tabs?
Video/Audio->Video
Local
You could just screenshot the parts other than network or anything you don’t want to share. I’m especially interested if it might be due to multicasting, though I can’t think of why this would matter.
This is the camera in question. Here’s the main stream:
and the substream:
Let me know if you want to see anything else. The rest is pretty typical. I don’t know what multicasting is, so unless it is enabled by default i’m not doing it. My DVR is plugged into a netgear R7960P router, as are my two pi4’s. One is running HA OS and the other running doods and node-red on raspbian.
I have a typical 1gbps down 40mbps up service through my cable company. Usually see around 600mbps down and 35 up.
FYI:
rtsp://192.168.1.168:10554/Streaming/channels/101 – get the mainstream of the 1st channel
rtsp://192.168.1.168:10554/Streaming/channels/102 – get the sub stream of the 1st channel
Yeah you have a bit of a different situation since you are getting your feed from the NVR. I am getting my stream straight from the camera, so it would be good to see your camera config if you know how to log into them. That’s where most of the important stuff is configured.
That’s basically identical to how mine are set up (main stream and substream are the same 10-20 second delay). I get a good framerate >1fps, but just a 10-20 second delay between the actual real life event and when I can see it on the frontend.
I’ll poke around, but don’t forget I’m using TVI cameras over coax, not ip cameras. But let me see if there’s more camera specific information in there.
Edit. I’m accessing the DVR through the hikvision iVMS-4200 application. The only other page of info related to camera streams is here (though this may be just related to PTZ control over coax?)
Ok so it is not a framerate issue or a comm issue. Somehow, your frames are getting buffered in memory before getting displayed. 10mins of frames is a lot. I have had similar issues while developing my ffmpeg component using a coroutine as I am a bit of a newb with python but ended up resolving it. Are you recording your stream somewhere? Is you camera for example recording to and SD card?
Nope, no recording. And I even tested turning off all the components except the stream: component and the camera: component and having a UI with only one card, the picture elements card with the camera feed and had the same issue. I can open the same feed in VLC on very similar hardware and see it in perfect near real time.
Oh and it’s 10 seconds, not 10 minutes, that was a typo.
Not sure if gifs load here, but if it helps, here’s a clip of my experience at home. Please let me know if you guys see something that I missed that should have been obfuscated:
I have a very similar experience… I am currently loading 16 streams in screen in less than 1s but that is because many of them are running live in the background.
My card also shows up relatively quickly when I load up the dashboard (though not as good as yours), and has good framerate. It’s just that what is displayed in the card is 10-20 seconds slower than what is happening in real life.
As I said above, my 640x480 Android IP Webcam stream from a cheap old phone over wifi to HA on a low-power Banana Pi M1 is immediate (I can hear traffic directly and watch it in HA with sub-second delay), and as smooth as the IP webcam frontend in the card itself, no need for the pop-up window.
The phone is also recording the stream and ftping it to the Pi every 15 minutes with no apparent slowdown.
Perhaps it’s the video format that’s the issue? I’m using MPEG4 as the phone is too old to cope with H.264/5.
ok, interesting topic here!
I have some Foscam c1 as well, they work well in lovelace, the stream is quite OK, alo have the 10 sec lag behind
But i have exposed them to my google HUB , its horrible to watch the camera streams there… always buffering…
i also have a Synology, (its virtualized on a ESXI server), same for ma HA…
i am running it on a HP Xeon server with more then enough memory, cpu …
i have tried the foscam , generic, onvif component, always lag…
now i am using the rtsp stream paths;, it gives the best results, but still horrible
what can i do to improve this? do i need to load that custom .py file? can it be loaded as custom component? do i need to change something also in that file?
I just installed a fresh homeassistant installation on a Pi3b+ and added only 1 camera… I got exactly the same result, without camera-view set to live I get 1 frame every 10 seconds or so and it when it refreshes, it’s maybe only 1 second behind, but when I switch to live view, I get 15 seconds of lag (which is actually 2-3 seconds behind my intel box I’m running now), even if I open and preload stream.
So it’s got to be something on the camera side. I’d love to see someone’s hikvision camera (not DVR) configuration that doesn’t have this issue. I’m running h.264 so to answer @Troon, that doesn’t seem to be any better than MPEG4.
To be clear, I’m running MPEG4 on old hardware and I do not have any delay issues.
EDIT: Just tried holding a phone showing the stream which has a clock overlaid on it in front of the camera whilst watching the stream on my laptop, and the delay is slightly over a second whilst running two simultaneous streams. Tried the same thing with the IP Webcam web front end, and the delay is about 3s, so HA is faster.
This always seems to have been an issue. I ended up setting up ffserver on a linux server and streaming my rtsp streams using ffserver/ffmpeg as mjpeg format. I had to seriously lower the size and resolution of the streams as well as lower the fps to 10 or less. This works great, however, it means that I’m always playing the video stream from each camera 24/7/365. I have over 20 cameras. This is a waste of resources as it’s highly CPU intensive an it causes a lot of additional I/O on the dvr disks as well as the Linux disk drive. I really wish my dvr and cameras supported mjpeg natively. This would make life so much easier.
Okay, holy crap, I finally figured it out and it was so damned simple.
I was playing with MJPG again based on your latest suggestions but only getting 1 frame every 10 seconds in my lovelace card and it wouldn’t open the detail view due to the fact that the streaming component was enabled and apparently that only works with h.264… So I commented out
stream:
in my lovelace config and when I restarted, all my h.264 cameras were near real time… The framerate in the frontend is only maybe .5-1 FPS, but there’s almost no lag (maybe 1-2 seconds), which is much more useful than the higher framerate… That’s all it was! Just turn of stream… Combine that with
camera_view: live
in the lovelace card, and everything works well.
Thanks @Troon , @rafale77, @Coolie1101 or bearing with me, you’ve been a great help in giving me hope that this was actually solvable. Now I feel confident to move forward with using hass for video doorbells and other things. @pergola.fabio, give it a try.