mrlt8 / docker-wyze-bridge

WebRTC/RTSP/RTMP/LL-HLS bridge for Wyze cams in a docker container
GNU Affero General Public License v3.0
2.64k stars 166 forks source link

Still Image #42

Closed binarynightowl closed 3 years ago

binarynightowl commented 3 years ago

I did not see an option in the docs for a still image, is there a workaround for this?

mrlt8 commented 3 years ago

There is no built-in way, but I could try adding something in the future if there's enough demand.

You could also hack together something in your docker-compose.yml to get a still image via an nginx container like this:

version: '3.8'
services:
    wyze-bridge:
        container_name: wyze-bridge
        image: mrlt8/wyze-bridge:latest
        restart: always
        ports:
            - 1935:1935
            - 8554:8554
            - 8888:8888
        environment:
            - WYZE_EMAIL=
            - WYZE_PASSWORD=
            # Should be able to append the following lines to your existing docker-compose.yml
            # jpg will be available at http://<server-ip>:8080/cam-name.jpg
            # Replace <MY-CAM-NAME-UPPER> and <my-cam-name-lower> for each cam:
            - RTSP_PATHS_<MY-CAM-NAME-UPPER>_RUNONPUBLISH=ffmpeg -hide_banner -nostats -loglevel fatal -i rtsp://0.0.0.0:8554/<my-cam-name-lower> -vframes 1 -y /img/<my-cam-name-lower>.jpg
            - RTSP_PATHS_<MY-CAM-NAME-UPPER>_RUNONPUBLISHRESTART=yes
            # Do the same for each additonal cam:
            - RTSP_PATHS_<MY-CAM-NAME-UPPER>_RUNONPUBLISH=ffmpeg -hide_banner -nostats -loglevel fatal -i rtsp://0.0.0.0:8554/<my-cam-name-lower> -vframes 1 -y /img/<my-cam-name-lower>.jpg
            - RTSP_PATHS_<MY-CAM-NAME-UPPER>_RUNONPUBLISHRESTART=yes
        volumes: 
            - stills-data:/img
    web:
        container_name: nginx
        image: nginx:mainline-alpine
        restart: always
        ports:
            - 8080:80
        volumes:
            - stills-data:/usr/share/nginx/html
volumes:
    stills-data:
        driver_opts:
            type: tmpfs
            o: size=8m
            device: tmpfs          

Not sure if the tmpfs actually works, but it's worth a try to save on writes to your local drive.

KennyStier commented 3 years ago

I gave this a try by writing to disk, but no JPGs were ever generated

mrlt8 commented 3 years ago

Did you set a volume for the images to be saved to?

joebetsill commented 3 years ago

Commenting to boost demand. Still images are apparently a requirement to use a rtsp stream in Home Assistant. I have not tried the workaround yet, but I'm using Synology's Docker Frontend instead of Docker Compose, so I have to figure out how to convert what you've suggested into something that works there.

A more integrated solution would be appreciated.

jon-heller commented 3 years ago

I followed these instructions and it worked, so thank you!

I also am using Home Assistant which requires a still image, so I could definitely see there being some demand for this.

mckochan commented 3 years ago

FYI still images are not required in home assistant if you use the ffmpeg camera integration. https://www.home-assistant.io/integrations/camera.ffmpeg/

It automatically generates the images every ~10 secs I have seen no downside to this myself vs generic cam.

joebetsill commented 3 years ago

FYI still images are not required in home assistant if you use the ffmpeg camera integration. https://www.home-assistant.io/integrations/camera.ffmpeg/

It automatically generates the images every ~10 secs I have seen no downside to this myself vs generic cam.

Whoa, thanks. I was over on Generic Camera. Maybe this requirement isn't in as much demand as it first seemed.

mrlt8 commented 3 years ago

Added some basic support for Home Assistant in v0.5.15 which should grab the thumbnail from the wyze servers and make it available as the still image using Home Assistant's http server.

xconverge commented 3 years ago

Any chance that can be utilized in the overall wyze-bridge image, not just the HA addon/environment? I am trying to get the least CPU intensive, still image provider possible from this container if possible

I would like to use the generic_camera in HA with a still image instead of the ffmpeg camera due to CPU. It would be nice to keep HA light and doing what it does best, and have this image doing what it does best (providing the image in various formats for others to consume)

I will start with the RUNONPUBLISH env method and see if I can get something going

mrlt8 commented 3 years ago

Sure, but you'll still need to supply your own http server via compose or grab the image from the container.

CPU usage should be minimal since it just grabs the thumbnail from the wyze server, but it only does this once at startup since those thumbnails aren't updated as often.

mrlt8 commented 3 years ago

Added API_THUMB to v0.5.18, which should save a thumbnail to /img/cam-nickname.jpg

xconverge commented 3 years ago

I cant get

Pulling thumbnail for {camera.nickname} from the Wyze API...

to print in my logs, and /img/ stays empty

I do however see the

Refreshing camera data for thumbnails

so I know API_THUMB is set...

HLS and RTSP are all good so I know its not locked up....

Any ideas am I missing something silly?

mrlt8 commented 3 years ago

Weird. Are you building from source? The thumbnails required some upstream patching, so you may need to rebuild with --no-cache

xconverge commented 3 years ago

And before I go farther, does the fetching occur periodically? Looking at the code threw me off a bit from what I expected

mrlt8 commented 3 years ago

No, only at startup because there doesn't seem to be any indication of how often those thumbnails get updated.

I've also been cautious of hitting the wyze api and try to keep the requests to a minimum.

xconverge commented 3 years ago

Sounds good, that is what I saw which made it a non-starter for my needs. I might just need to use the wyzecam python library and figure something out to get still images the way I would like. Thanks for your work on this so far though!

mrlt8 commented 3 years ago

I created a branch that would use ffmpeg to save an image every 180. Let me know what you guys think!

xconverge commented 3 years ago

I think if that 180 is an env variable too you have a winner that would be hard to argue with!

mrlt8 commented 3 years ago

Merged into the main branch with a configurable RTSP_THUMB e.g:

RTSP_THUMB=true
or
RTSP_THUMB=300
mckochan commented 3 years ago

Do we have to mount the /img/ folder when using docker-compose to be able to access it? If so, does anyone have an example?

xconverge commented 3 years ago

just like any other volume:

volumes:
  - '/path/on/host/wyzebridgeimages:/img'
xconverge commented 3 years ago

@mrlt8 tested it and it works great, thanks a bunch, I think you can probably consider this feature added/closed now!

Zoubrow commented 3 years ago

Hello, i've added RTSP_THUMB=true but i have no image created in /img

i've tried with both API_THUMB=true and RTSP_THUMB=true and with both at the same time and i have nothing in /img

Do you have any idea what could cause this issue ?

my docker-compose.yml file:

version: '3'
services:
  wyze-bridge:
    container_name: wyze-bridge
    restart: unless-stopped
    image: mrlt8/wyze-bridge:latest
    ports:
      - 1935:1935
      - 8554:8554
      - 8888:8888
    networks:
      - backend
    volumes:
      - ./wyze-bridge/img/:/img
      - /etc/localtime:/etc/localtime:ro
    environment:
      - WYZE_EMAIL=${WYZE_EMAIL}
      - WYZE_PASSWORD=${WYZE_PASSWORD}
      - RTSP_THUMB=true
      - RTSP_PATHS_ALL_READUSER=${RTSP_USER}
      - RTSP_PATHS_ALL_READPASS=${RTSP_PASS}

networks:
  frontend:
    external: true
    name: proxynet
  backend:

my docker logs:

wyze-bridge          | 2021/09/23 23:10:51 I [0/0] rtsp-simple-server v0.17.3
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [RTSP] TCP listener opened on :8554
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [RTMP] listener opened on :1935
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [HLS] listener opened on :8888
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [API] listener opened on 127.0.0.1:9997
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [HLS] [muxer baby-cam] created
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [path baby-cam] created
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [HLS] [muxer baby-cam] ERR: no one is publishing to path 'baby-cam'
wyze-bridge          | 2021/09/23 23:10:51 I [0/0] [HLS] [muxer baby-cam] destroyed
wyze-bridge          |
wyze-bridge          | 🚀 STARTING DOCKER-WYZE-BRIDGE v0.6.7
wyze-bridge          | 2021/09/23 23:10:51 [MainThread] 🔍 Could not find local cache for 'user'
wyze-bridge          | 2021/09/23 23:10:51 [MainThread] 🔍 Could not find local cache for 'auth'
wyze-bridge          | 2021/09/23 23:10:51 [MainThread] ☁️ Fetching 'auth' from the Wyze API...
wyze-bridge          | 2021/09/23 23:10:52 [MainThread] 💾 Saving 'auth' to local cache...
wyze-bridge          | 2021/09/23 23:10:52 [MainThread] ☁️ Fetching 'user' from the Wyze API...
wyze-bridge          | 2021/09/23 23:10:53 [MainThread] 💾 Saving 'user' to local cache...
wyze-bridge          | 2021/09/23 23:10:53 [MainThread] 🔍 Could not find local cache for 'cameras'
wyze-bridge          | 2021/09/23 23:10:53 [MainThread] ☁️ Fetching 'cameras' from the Wyze API...
wyze-bridge          | 2021/09/23 23:10:54 I [0/0] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:10:54 I [0/0] [HLS] [muxer baby-cam] created
wyze-bridge          | 2021/09/23 23:10:54 I [0/0] [HLS] [muxer baby-cam] ERR: no one is publishing to path 'baby-cam'
wyze-bridge          | 2021/09/23 23:10:54 I [0/0] [HLS] [muxer baby-cam] destroyed
wyze-bridge          | 2021/09/23 23:10:54 [MainThread] 💾 Saving 'cameras' to local cache...
wyze-bridge          |
wyze-bridge          | 🎬 STARTING ALL 1 CAMERAS
wyze-bridge          | 2021/09/23 23:10:54 I [0/0] reloading configuration (API request)
wyze-bridge          | 2021/09/23 23:10:57 [Baby Cam] 🎉 Starting 1080p 120kb/s Stream for WyzeCam V3 in "LAN mode" FW: 4.36.3.19 IP: 192.168.1.6 WiFi: 94%
wyze-bridge          | 2021/09/23 23:10:58 I [0/0] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:10:58 I [0/0] [HLS] [muxer baby-cam] created
wyze-bridge          | 2021/09/23 23:10:58 I [0/0] [HLS] [muxer baby-cam] ERR: no one is publishing to path 'baby-cam'
wyze-bridge          | 2021/09/23 23:10:58 I [0/0] [HLS] [muxer baby-cam] destroyed
wyze-bridge          | 2021/09/23 23:11:04 I [0/0] [RTSP] [conn 127.0.0.1:36748] opened
wyze-bridge          | 2021/09/23 23:11:04 I [0/0] [RTSP] [session 769190765] opened by 127.0.0.1:36748
wyze-bridge          | 2021/09/23 23:11:04 I [1/0] [RTSP] [session 769190765] is publishing to path 'baby-cam', 1 track with TCP
wyze-bridge          | 2021/09/23 23:11:06 I [1/0] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:11:06 I [1/0] [HLS] [muxer baby-cam] created
wyze-bridge          | 2021/09/23 23:11:06 I [1/1] [HLS] [muxer baby-cam] is converting into HLS
wyze-bridge          | 2021/09/23 23:11:11 I [1/1] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:11:12 I [1/1] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
wyze-bridge          | 2021/09/23 23:11:14 I [1/1] [HLS] [conn 192.168.1.10:64585] GET /baby-cam/stream.m3u8
mrlt8 commented 3 years ago

RTSP_THUMB will automatically disable API_THUMB. Can you try API_THUMB without RTSP_THUMB?

I've also updated the ffmpeg command to grab the image from 127.0.0.1 instead of localhost to avoid any network issues.