FiveLeavesLeft / WyzeCameraLiveStream

Hack to allow live streaming from wyze cameras to vlc or mpv on your desktop.
MIT License
101 stars 7 forks source link

homebridge configuration #5

Open nijhawank opened 3 years ago

nijhawank commented 3 years ago

While I could see the RTSP stream on macOS with VLC, my hoobs based home bridge installation is not working. Can you provide the homebridge-ffmpeg configuration that you used to stream the camera to HomeKit.

mrlt8 commented 3 years ago

Haven't done much testing, but here's a basic config for Camera-ffmpeg that should get you started:


{
                    "name": "Wyze",
                    "videoConfig": {
                        "source": "-i http://CAMIP:12345",
                        "stillImageSource": "-i http://CAMIP:12345 -vframes 1 -r 1",
                        "vcodec": "copy",
                        "additionalCommandline": "-pix_fmt yuv420p -re -force_key_frames -x264-params intra-refresh=1:bframes=0",
                        "maxStreams": 2,
                        "maxWidth": 1920,
                        "maxHeight": 1088,
                        "maxBitrate": 1200,
                        "audio": false,
                        "packetSize": 188,
                        "maxFPS": 15
                    }
                }
nijhawank commented 3 years ago

It worked.

FiveLeavesLeft commented 3 years ago

Seems like this has been resolved. Closing.

mrlt8 commented 3 years ago

@FiveLeavesLeft Can we keep this open for a while?

I'd like to see what other people are using or if anyone has some improvements to add.

FiveLeavesLeft commented 3 years ago

@mrlt8 . Sure, reopening.

nijhawank commented 3 years ago

Though it works, there’s a big delay (6-7 seconds) at the opening of steam. Also I see this error messages in the home bridge logs like below…

5/3/2021, 8:49:25 AM [Camera FFmpeg] [Wyze] [Snapshot] Last message repeated 1 times 5/3/2021, 8:49:25 AM [Camera FFmpeg] [Wyze] [Snapshot] [h264 @ 0x2414290] decode_slice_header error 5/3/2021, 8:49:25 AM [Camera FFmpeg] [Wyze] [Snapshot] [h264 @ 0x2414290] no frame! 5/3/2021, 8:49:30 AM [Wyze] The image snapshot handler for the given accessory is slow to respond! See https://git.io/JtMGR for more info. 5/3/2021, 8:49:31 AM [Camera FFmpeg] [Wyze] Fetching snapshot took 6.086 seconds. It is highly recommended you switch to unbridge mode. 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] Starting video stream: native x native, native fps, ??? kbps 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] decode_slice_header error 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] no frame! 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] decode_slice_header error 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] no frame! 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] decode_slice_header error 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] no frame! 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] non-existing PPS 0 referenced 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] decode_slice_header error 5/3/2021, 8:49:33 AM [Camera FFmpeg] [Wyze] [h264 @ 0x24c27f0] [error] no frame! 5/3/2021, 8:49:39 AM [Camera FFmpeg] [Wyze] Getting the first frames took 5.929 seconds. 5/3/2021, 8:50:00 AM [Camera FFmpeg] [Wyze] Stopped video stream.

FiveLeavesLeft commented 3 years ago

@nijhawank , is this with the version I released yesterday or the previous version? This is kind of expected because h264 frames have several different types and the software needs to wait until one of a particular type arrives. The new version will get rid of the errors messages but the delay will still be there.

nijhawank commented 3 years ago

This is the previous version. Do I have to reflash your new version, or just an updated libimp.so would suffice? If that's the case, can you please provide the link to the update libimp.so

mrlt8 commented 3 years ago

I made some tweaks to my original config:

    {
        "name": "CAM-NAME",
        "manufacturer": "Wyze",
        "model": "Cam v2",
        "unbridge": true,
        "videoConfig": {
            "source": "-i http://CAM-IP:12345",
            "stillImageSource": "-i http://CAM-IP:12345 -vframes 1 -r 1",
            "vcodec": "copy",
            "maxStreams": 1,
            "audio": false,
            "packetSize": 188
        }
    }

I removed most of the extra setting since I couldn't really see any noticeable difference. (about 5-8 seconds to load first frame) Added unbridge to prevent the camera from slowing down the homebridge. Could probably also remove stillImageSource without any negatives.

@nijhawank I don't think there is much more that can be tweaked in homebridge to get the camera to load any faster since the stream has a similar delay in VLC (keyframe issue?). You could try playing around with some additionalCommandline options https://ffmpeg.org/ffmpeg-formats.html to see if that will get rid of some of your errors.

romedtino commented 3 years ago

It's probably very similar to the HomeBridge settings but in case anyone is interested in using this on Frigate for Home Assistant sees this, here's settings that work for me

Frigate for Home Assistant ```yaml wyzefront: ffmpeg: # hwaccel_args: # - -hwaccel # - vaapi # - -hwaccel_device # - /dev/dri/renderD128 # - -hwaccel_output_format # - yuv420p input_args: - -avoid_negative_ts - make_zero inputs: - path: http://x.x.x.x:12345 roles: - detect - clips - rtmp width: 1920 height: 1080 fps: 5 clips: # Required: enables clips for the camera (default: shown below) # This value can be set via MQTT and will be updated in startup based on retained value enabled: True # Optional: Number of seconds before the event to include in the clips (default: shown below) pre_capture: 5 # Optional: Number of seconds after the event to include in the clips (default: shown below) post_capture: 5 # Optional: Objects to save clips for. (default: all tracked objects) objects: - person ```

My hardware acceleration is turned off for other reasons but the important parts are the import_args otherwise, you'll get a green video

mckochan commented 3 years ago

@romedtino Thanks for this. Are you getting good results with Frigate? I can't seem to stream for more than 10 sec without it losing connection. MPV seems to work fine. I also cannot get the stream into home assistant driectly, although it will show the static image updated every 10 sec in lovelace.

mrlt8 commented 3 years ago

Here's my config to get motion notification/automation in homekit/homebridge:

#!/bin/sh

SLEEP=10
BRIDGE=<homebridge ip and "HTTP port" set earlier>
CAMERA=<cam name in homebridge>

while : ; do
    sleep $SLEEP
    JPG=$(ls -t /media/mmc/alarm/$(date +'%Y%m%d')/*.jpg | head -n 1)
    [[ $(echo $JPG | wc -w) -eq 0 ]] && continue
    [[ -z ${LAST+x} ]] && LAST=$JPG && continue
    if [[ $JPG != $LAST ]]; then
        wget -q -O - "http://$BRIDGE/motion?$CAMERA"
        LAST=$JPG
    fi
done

You can auto start the script by calling it from export CUSTOM_SCRIPT= in /configs/wyze_hack.cfg

noelhibbard commented 3 years ago

/media/mmc/alarm doesn't even exist on my v3.

Hmm.. I did see a /tmp/alarm_1.jpg that was there while it was recording and then went away when it was done. So maybe you could watch for that on a V3.

mrlt8 commented 3 years ago

/media/mmc/alarm doesn't even exist on my v3.

Do you have an SD card in the cam? Not sure if they changed things on the v3, but that's where it saves the 'events' on the v2.

You could monitor the tmp folder with something like this:

#!/bin/sh
SLEEP=10
BRIDGE=homebridge-ip:port
CAMERA=camera-name-in-homebridge

while : ; do
    [[ -f /tmp/*.jpg ]] && wget -q -O - "http://$BRIDGE/motion?$CAMERA"
    sleep $SLEEP
done 

or substitute *.jpg with alarm_* to check for alarm_1.jpg and alarm_record_1.mp4

but, as you noticed, the file get removed so there's a chance you could miss an event..? I also noticed that the camera writes a log to /tmp/metric.log, so you might be able to parse and monitor that file.

Either way, all methods seem to suffer from the 300 second cool down.

noelhibbard commented 3 years ago

Yeah I did something similar like this:

#!/bin/sh

alarmfile="/tmp/alarm_*.jpg"
alarmactive=false

while true
do
    if [ -f $alarmfile ] ; then
        if [ "$alarmactive" = false ] ; then
            alarmactive=true
            wget -O - "http://blablabla.com" > /dev/null 2>&1
        fi
    else
        alarmactive=false
    fi
    sleep 1
done

I'm using it to call a nodejs app running on another server that then sends a message to a Telegram group. I would directly send a telegram but wget on the camera doesn't support HTTPS and the Telegram APIs only support HTTPS.

BTW, I don't see /tmp/metric.log on my V3.

ikrowni commented 3 years ago

My hardware acceleration is turned off for other reasons but the important parts are the import_args otherwise, you'll get a green video

Which hardware acceleration options should be turned on for a v3 cam?

jrbecart commented 3 years ago

@romedtino

Do you know how to display the feed in HA without frigate?

I tried this without luck:

camera:
  - platform: ffmpeg
    input: http://x.x.x.x:12345
romedtino commented 3 years ago

@romedtino

Do you know how to display the feed in HA without frigate?

I tried this without luck:

camera:
  - platform: ffmpeg
    input: http://x.x.x.x:12345

Sorry I do not. I did need to add

-avoid_negative_ts  make_zero

to my ffmpeg input arguments for frigate, hope that helps!