Why are IP cameras so slow in frontend?!

Just comment it out. opencv/mpeg will detect the formats. This is only to force a specific decoder.

Ok thanks.

Iā€™d love to know how you get on with this. I have the same setup and use Frigate (as Iā€™m aware you do) to display the live camera feeds from that. Doing this directly in HA would reduce the 10+ second delay on the frontend without involving Frigate, and make everything much smoother!

So far it didnā€™t change anything when put into custom_components. I guess Iā€™ll dive into the container and try to change it there and see if thereā€™s any difference.

So when I replace the file in the container and check the config I get:

Platform error camera.ffmpeg - No module named 'cv2'

I did install opencv-python on the host OS, in the hopes it would be inherited by the container, but that doesnā€™t seem to have happened.

Yeah thatā€™s an illustration as to why I donā€™t use containers for applications like Home Assistantā€¦ When you have so many components with dependencies and the program is as large and variable as it is, it just makes no sense to me. It seems like you will need to find a way to get it installed in the container. Maybe try creating a dummy opencv component in your setup which will force the dependency download?

That was a good idea, adding

image_processing:
  - platform: opencv

to my configuration.yaml got rid of the errorā€¦ Unfortunately even after that, the camera delay is no betterā€¦ Itā€™s actually a bit worse. I wonder if it has something to do with GPU use?

Out of curiosity, could you describe what kind of hardware you are using and what kind of latency you get when compared to the live action to when you see the update on the video? Iā€™d be willing to add GPU if I thought it could address the latency issues. Thanks for trying to help out with my issues.

I have 0 latency. I am running all this on a ubuntu VM using a single thread (half a core) of an i7 6700K with a bunch of other programs related to home automation. I did bridge in an RTX2070 for programs in the VM to run a bunch of video inferencesā€¦

This may no provide any value, but I have a dumb simple little Swann (hikvision) 8 cam system. TVI cams over coax to network attached DVR - super simple consumer grade stuff. Iā€™m using the hikvision integration to grab the streams over rstp. I have one stream set to preload, and have it on my default Lovelace view. That stream seems to load almost instantly and has just about no lag. The experience is just about comparable to accessing the streams via the Swann app.

I tried using the onvif integration and had a poor experience compared to the hikvision route. Much like what you guys are describing.

Not sure if this helps, but wanted to share my positive experiences streaming over that integration. Iā€™m running vanilla home assistant os on an rpi4 fwiw.

Interesting, I also have hikvision cams, maybe I can make this work too. So far my lowest latency is via the synology integration, which is around 5 seconds when it refreshes, compared to 10-20 with default or ffmpeg cameras.

Okay, off to try that I guess.

Hmm, I just tried to google the hikvision camera platform but came up empty handed (assumed this must be new because I thought I would have noticed it earlier). Could you double check exactly what integration it is you are using?

Iā€™m sorry. Iā€™m an idiot. Iā€™m using the hikvision integration for motion and event reporting, and the generic camera integration for the rtsp streams. So my experience is that using generic camera is better than onvif.

I have no idea how any of this actually works, but if it helps, Iā€™m currently not using SSL on anything on the local network. So http into Lovelace. Over nabu casa, connecting over LTE, thereā€™s about a 5 second delay before the stream goes live. No real lag after itā€™s up and running.

No problem, just wanted to make sure I didnā€™t miss something. Is there any way I could get you to check your config and see how it compares to the below? I am also using local non-ssl connection when measuring latencyā€¦ I wonder whatā€™s differentā€¦?

  - platform: generic
    name: Cam1
    still_image_url: http://username:[email protected]/Streaming/Channels/1/picture
    stream_source: rtsp://username:[email protected]:554/Streaming/Channels/101/
    framerate: 4

I use the generic stream as well for hikvision cams and it seems to work fine. I get the streams from my NVR and use the substreams for most cams, but may upgrade to the full 4k stream in some instances (just not sure how well HA deals with H265+). This is how my cameras are set up in configuration.yaml

stream:
camera:
  - platform: generic
    name: Front 1
    still_image_url: "http://USER:[email protected]/ISAPI/Streaming/channels/101/picture"
    stream_source: "rtsp://USER:[email protected]:554/Streaming/Channels/102?transportmode=unicast&profile=Profile_1"
  - platform: generic
    name: Front 2
    still_image_url: "http://USER:[email protected]/ISAPI/Streaming/channels/201/picture"
    stream_source: "rtsp://USER:[email protected]:554/Streaming/Channels/202?transportmode=unicast&profile=Profile_1"

and the cards are set up like this

    cards:
      - type: picture-entity
        camera_view: live
        entity: camera.front_1
      - type: picture-entity
        camera_view: live
        entity: camera.front_2
name: Camera - Front Porch
    still_image_url: "http://user:[email protected]:85/ISAPI/Streaming/channels/101/picture"
    stream_source: "rtsp://user:[email protected]:554/Streaming/channels/101"

I think X01 is the substream, but I have my substreams set to a pretty decent resolution. Good enough to see whatā€™s going on, and good enough for DOODS. maybe thatā€™s the difference. Iā€™m viewing much lower resolution.

Edit: these are the main streams at 1080p@12fps

So I tried duplicating your configuration but I didnā€™t get any change in the 10-20 second lag on the cameras. Itā€™s the same story for the main stream and substream. Iā€™m at a loss at this point. Itā€™s very frustrating to hear about people on the same cameras as me with everything working perfectly.

Maybe itā€™s just that Iā€™m on a 2011 mac mini and missing some processor functions it needs or maybe something else in my config is somehow affecting it. But I can go to the stream myself with VLC on another mac with a 2011 processor and itā€™s quite fast. Iā€™m tempted to just restart with a very simple ā€œcamera onlyā€ config and see if I still have the same issue.

Out of curiosity, what server hardware and hass install are you running?

Is there anything I would have to do specially on the camera config to get multicast support from the camera? Maybe thatā€™s something you do differently? I didnā€™t specifically set up multicastā€¦ Do you have a multicast address defined at the bottom of the IP config of the camera/DVR
image
and is that the address you use in your camera config within hass?

So, just to take this to the extreme and be sure it had nothing to do with my hass configuration, I commented out everything in my entire config.yaml and lovelace-ui.yaml except 1 camera with only the substream going configured exactly as @D34DC3N73R described, and I had the exact same delay as beforeā€¦ Even with everything enabled, Iā€™m only at about 20% CPU and RAM and 40% diskā€¦ Ughā€¦

So itā€™s got to be something in the camera config or something wrong with my server hardware. I donā€™t think itā€™s something in my hass config.

No itā€™s not, this is the normal behavior, see post linked below.

Thatā€™s very old information that is from before the stream component became available.

I used to have my cameras configured exactly that way but I had the 10+ second delay in the lovelace card and only 1 frame every 10 seconds. If I clicked on it to get the detail view, I could get 1 frame every 5 seconds with almost real time update.

I still have some cameras configured this way for automatic popup on my kiosk tablets when people are spotted outside to give a slightly more realtime viewā€¦ But not really very good with such a low framerate.

The guys above seem to have it working with the stream component, which means a good framerate of more than 1 FPS and realtime view in the lovelace card (at least from what it sounds like). Thatā€™s what I want. I already have 10 second delay with good framerate, so going back to 1 frame every 10 seconds isnā€™t an upgrade.