seydx / homebridge-camera-ui

Homebridge plugin for RTSP Cameras with HSV, motion detection support, Image Rekognition, Web UI to manage/watch streams and WebApp support
MIT License
621 stars 92 forks source link

Use internal RTSP server #334

Open macjl opened 2 years ago

macjl commented 2 years ago

Is your feature request related to a problem? Please describe. The prebuffer stream use the pipe muxer, to split streams for videoanalysis, HSV, live video, etc. It also use the mpegts mixer that can cause problems with some input sources.

Describe the solution you'd like The prebuffer stream could use an internal rtsp server instead of pipe. All transforms to the video input could be made just before being sent to this internal rtsp server. For example : reencode the stream if not H264, transpose the image, etc...

Describe alternatives you've considered I already use an external rtsp server for that purpose. It's working well, but by making it integrated to camera.ui would be easier for other users.

Additional context The configuration of my external rtsp server, bases on containers :

docker-compose.yml :

version: '3.7'
services:
  homebridge:
    image: oznu/homebridge:latest
    container_name: homebridge
    restart: always
    network_mode: host
    environment:
      - PGID=1000
      - PUID=1000
      - HOMEBRIDGE_CONFIG_UI=1
      - HOMEBRIDGE_CONFIG_UI_PORT=8085
    volumes:
      - /homebridge

  rtsp:
    image: aler9/rtsp-simple-server
    restart: always
    environment:
      - RTSP_PROTOCOLS=tcp
    ports:
      - 8554:8554

  ffmpeg-usbcam:
    image: oznu/homebridge
    restart: always
    devices:
      - /dev/video0
      - /dev/snd
    entrypoint: /bin/exec
    command: /bin/sh -c "apk add alsa-utils && ffmpeg -thread_queue_size 512 -fflags +genpts -f video4linux2 -framerate 10 -video_size hd720 -i /dev/video0 -thread_queue_size 512 -fflags +genpts -f alsa -ac 1 -ar 32k -i default:CARD=C615 -map 0:v -map 1:a -codec:v libx264 -preset:v ultrafast -profile:v baseline -level:v 3.1 -tune zerolatency -pix_fmt yuv420p -r 10 -b:v 2000k -force_key_frames 'expr:eq(t,n_forced*4)' -bsf:a aac_adtstoasc -acodec libfdk_aac -profile:a aac_low -ar 32k -b:a 64k -ac 1 -shortest -f rtsp rtsp://rtsp:8554/live/usbcam.stream"

config.json :

{
    "name": "UsbCam",
    "motion": true,
    "hsv": true,
    "prebuffering": true,
    "videoConfig": {
        "source": "-i rtsp://localhost:8554/live/usbcam.stream",
        "vcodec": "copy",
        "acodec": "copy",
        "audio": true
    },
    "videoanalysis": {
        "active": true
    }
}
seydx commented 2 years ago

Added to project v5.1.0

https://github.com/seydx/homebridge-camera-ui/projects/1

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.