Amcrest Camera Feed - How to Prevent Going Blank/White After a few Seconds If Clicked Into from HA?

I have a few Amcrest IP cameras configured with HA. They provide a nice quick visual of what’s happening and work fairly consistently.

As soon as I click/tap into one of the camera feeds, I get a larger view of the “live stream” (really updates ever X number of seconds). After ~5 seconds, the screen goes blank/white and I am no longer shown the “live stream.” After clicking the X to go back to my Home UI, I still see the “live stream” via the smaller visual, so it’s still working.

Any ideas as to what’s happening? And if so, is there a configuration setting that would allow it to continue streaming the feed?

There are several things you can do. I think the problem is the resolution is too high and frame rate is to much. I wasn’t happy with the performance when accessing my Amcrest IP Cam so I played around with various options until I found something that worked well.

One thing you my want to so is figure out the various URLs your camera supports. ispy is a good place for that: https://www.ispyconnect.com/man.aspx?n=Amcrest

If it has a substream, you can modify the settings to use something other than h.264. For instance, mine supports mjpeg. I can switch it to mjpeg and drop the frame rate down to 15 and access it through HA using the mjpeg camera type and its mjpeg url. The resolution will be smaller, probably 640x480 but even on my laptop, the quality is still excellent.

If it has rtsp support, you can use ffmpeg. For instance, I use ffmpeg with the substream set to h.264 and use the -r 15 argument to limit to 15 fps.

Another option is to use ffserver to transcode the rtsp stream into something else such as mjpeg. Then use the mjpeg camera type to view it. I find this to be the best way as the stream is always available and you don’t have to wait for ha to fire up an ffmpeg stream as the mjpeg stream is always running. Accessing an ffserver mjpeg stream from HA or HADashboard loads instantly.

1 Like

Are you using the Amcrest Hub component? And do you often see errors in the log? If so, I found that there is a bug in the code that makes it not thread-safe. I fixed the problem for myself, and added quite a few other features, but unfortunately given everything else going on I haven’t gotten around to feeding this back to the developer(s) of this component.

If you’re interested in what I’ve done, you can look here. Note this is not very well documented since so far I really haven’t shared this work. But you’re more than welcome to try what I did (if you’re comfortable with hand installing custom components.)

Regarding the thread-safety issue, basically the camera doesn’t like when multiple long commands are pending. (This applies to more than just the camera feeds, e.g., background motion detection monitoring, etc.) When you click on the image in the frontend, and you see the larger box open, what’s happening is now you have two views trying to show the same feed (which, by default, is using the camera’s snapshot API command.) The normal view only grabs a new image every 10 seconds, but the larger one tries to grab snapshots as fast as possible. When these two “collide”, the camera responds with errors.

Since there are many ways to configure HA to work with Amcrest cameras, and there are lots of Amcrest models, and lots of different firmware versions, the above discussion may or may not apply in your scenario.

1 Like

I am having issues with the Amcrest component connecting to an Amcrest IP4M-1028E 4MP camera. I can’t make it work via MJPEG or RTSP. I want to use the Amcrest component and not a generic MJPEG or FFMPEG component becuase I’m also using the Amcrest Motion Detection sensor in an automation. What I really want is RTSP to the camera’s “sub stream” which would be configured for H265 640x480 @ 20 FPS. That makes for a very low network throughput to HA relative to my main stream that is pumping out a H265 4MP @ 20 FPS stream to my Amcrest NVR. I tried configuring the sub stream for MJPEG, H265, and H264. All options result in no video being presented in the pop-up video viewer. It doesn’t even draw one frame. The snapshot image in the front end does appear correctly. My thought is the HA component is attempting to connect to the main stream and it is too much data to render. I assumed the “resolution: low” option would point the RTSP connection to the sub stream but it doesn’t appear so. I’ve tried about 20 combinations of settings with no luck. Nothing of interest is in the HA log except when I changed the port to 554 I got a “connection refused” in HA log. Is there an FFMPEG log file I should be looking at? How can I verify/edit what camera URL HA uses to change the stream it connects to?

Present Configuration:

ffmpeg:
  ffmpeg_bin: /usr/bin/ffmpeg
    
amcrest:
  - name: Test Camera
    host: 192.168.45.11
    username: !secret amcrest_user
    password: !secret amcrest_pw
    stream_source: rtsp
    resolution: low
    scan_interval: 1
    sensors:
      - motion_detector
    switches:
      - motion_detection

Note the scan_interval:1 is because I’m using the motion detection sensor to turn on my front porch lights in an automation. There is a pretty major delay in a motion event triggering this automation. I assumed HA has to poll the motion status from the camera and this scan_interval is the poll timer? Any insight on how this works would be appreciated also. Thanks!

Hi! In case you’re not aware, there have been recent updates to address some of the issues you were experiencing. If you haven’t already done so, try updating to the latest release and trying again, and especially try using the new stream component.

FWIW, the scan_interval configuration variable is broken and probably has been for a long time. The sensor will update every 10 seconds no matter what you set for scan_interval. I am looking into fixing that, though.