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
638 stars 92 forks source link

Prebuffering error on new install "too many packets buffered for output stream" #348

Closed leithma closed 2 years ago

leithma commented 2 years ago

I just set up a new instance with an Insteon camera, everything works until I try to prebuffer the feed (on any camera I try).

I just keep getting "FFmpeg prebuffer process exited with error! (null) - Too many packets buffered for output stream 0:0."

1/15/2022, 2:22:18 PM] [CameraUI] Front of House: Prebuffering command: C:\Users\leith\AppData\Roaming\npm\node_modules\homebridge-camera-ui\node_modules\ffmpeg-for-homebridge\ffmpeg.exe -hide_banner -loglevel error -fflags +genpts -i rtsp://[NAME]:[PASSWORD}@[LOCLAIP]:25109/videoMain -vcodec copy -bsf:a aac_adtstoasc -acodec libfdk_aac -profile:a aac_low -flags +global_header -ar 8k -b:a 100k -ac 1 -f tee -map 0:v? -map 0:a? [movflags=frag_keyframe+empty_moov+default_base_moof:f=mp4]tcp://127.0.0.1:11942|[f=mpegts]tcp://127.0.0.1:14558 [1/15/2022, 2:22:25 PM] [CameraUI] Front of House: FFmpeg prebuffer process exited with error! (null) - Too many packets buffered for output stream 0:0. [1/15/2022, 2:22:25 PM] [CameraUI] Front of House: Prebufferring process closed [1/15/2022, 2:22:25 PM] [CameraUI] Front of House: Restart prebuffer session..

seydx commented 2 years ago

Hey @leithma

can you post your config.json pls

and also tried without audio?

leithma commented 2 years ago

Thanks @seydx, Sure thing

{ "name": "CameraUI", "port": 8081, "atHomeSwitch": true, "debug": true, "mqtt": { "active": false }, "http": { "active": false, "localhttp": false }, "smtp": { "active": false }, "ftp": { "active": false }, "ssl": { "active": false }, "cameras": [ { "name": "Old Non-HD", "manufacturer": "Insteon", "motionTimeout": 15, "unbridge": true, "hsv": true, "prebuffering": false, "prebufferLength": 4, "videoConfig": { "source": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240", "subSource": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",

    "audio": true
  },
  "videoanalysis": {
    "active": false
  },
  "mqtt": {}
},
{
  "name": "Front of House",
  "manufacturer": "Insteon",
  "model": "2864-222",
  "serialNumber": "FIOCA1411002719",
  "excludeSwitch": false,
  "privacySwitch": true,
  "motion": true,
  "motionTimeout": 15,
  "unbridge": true,
  "hsv": true,
  "prebuffering": true,
  "forcePrebuffering": false,
  "prebufferLength": 4,
  "videoConfig": {
    "source": "-i rtsp://[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain",
    "subSource": "-i rtsp:[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain",
    "stillImageSource": "-i http://[LOCALIP]:25109/cgi-bin/CGIProxy.fcgi?usr=[USERNAME]&pwd=[PASSWORD]&cmd=snapPicture2",
    "readRate": false,
    "maxStreams": 2,
    "maxWidth": 1280,
    "maxHeight": 720,
    "maxFPS": 20,
    "forceMax": false,
    "audio": true,
    "debug": true
  },
  "videoanalysis": {
    "active": false
  },
  "mqtt": {}
}

] }

seydx commented 2 years ago

@leithma

try this config

{
  "name": "CameraUI",
  "port": 8081,
  "atHomeSwitch": true,
  "debug": true,
  "mqtt": {
    "active": false
  },
  "http": {
    "active": false,
    "localhttp": false
  },
  "smtp": {
    "active": false
  },
  "ftp": {
    "active": false
  },
  "ssl": {
    "active": false
  },
  "cameras": [
    {
      "name": "Old Non-HD",
      "manufacturer": "Insteon",
      "motionTimeout": 15,
      "unbridge": true,
      "hsv": true,
      "prebuffering": false,
      "prebufferLength": 4,
      "videoConfig": {
        "source": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",
        "subSource": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",
        "stillImageSource": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",
        "rtspTransport": "tcp",
        "vcodec": "copy",
        "acodec": "libfdk_aac",
        "audio": true
      },
      "videoanalysis": {
        "active": false
      },
      "mqtt": {}
    },
    {
      "name": "Front of House",
      "manufacturer": "Insteon",
      "model": "2864-222",
      "serialNumber": "FIOCA1411002719",
      "excludeSwitch": false,
      "privacySwitch": true,
      "motion": true,
      "motionTimeout": 15,
      "unbridge": true,
      "hsv": true,
      "prebuffering": true,
      "forcePrebuffering": false,
      "prebufferLength": 4,
      "videoConfig": {
        "source": "-i rtsp://[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain",
        "subSource": "-i rtsp:[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain",
        "stillImageSource": "-i http://[LOCALIP]:25109/cgi-bin/CGIProxy.fcgi?usr=[USERNAME]&pwd=[PASSWORD]&cmd=snapPicture2",
        "rtspTransport": "tcp",
        "vcodec": "copy",
        "acodec": "libfdk_aac",
        "audio": true,
        "debug": true
      },
      "videoanalysis": {
        "active": false
      },
      "mqtt": {}
    }
  ]
}

if this also doesnt work, disable audio and try again

leithma commented 2 years ago

@seydx I have not tried your config, but it does seem that if I toggle audio to false it works as expected.

seydx commented 2 years ago

@seydx I have not tried your config, but it does seem that if I toggle audio to false it works as expected.

Try also my config with audio enabled pls to be sure its really not working because of audio

leithma commented 2 years ago

@seydx

Still Errors with your config "[1/15/2022, 2:52:06 PM] [CameraUI] Front of House: FFmpeg prebuffer process exited with error! (null) - Too many packets buffered for output stream 0:0."

Alos side note :) can you edit your config and blank out the username and password I missed on the "stillImageSource": line

leithma commented 2 years ago

@seydx

If I toggle Audio on your config it works again.

seydx commented 2 years ago

Alos side note :) can you edit your config and blank out the username and password I missed on the "stillImageSource": line

Done :)

seydx commented 2 years ago

@seydx

If I toggle Audio on your config it works again.

Its working with my config and audio enabled?

leithma commented 2 years ago

@seydx :) thanks on the PW

and, no on the audio.. if I enable audio it fails

seydx commented 2 years ago

@seydx :) thanks on the PW

and, no on the audio.. if I enable audio it fails

Can you add following at the end of your camera source and try again WITH audio pls

-max_muxing_queue_size 1024

your config should look like

{
  "name": "CameraUI",
  "port": 8081,
  "atHomeSwitch": true,
  "debug": true,
  "mqtt": {
    "active": false
  },
  "http": {
    "active": false,
    "localhttp": false
  },
  "smtp": {
    "active": false
  },
  "ftp": {
    "active": false
  },
  "ssl": {
    "active": false
  },
  "cameras": [
    {
      "name": "Old Non-HD",
      "manufacturer": "Insteon",
      "motionTimeout": 15,
      "unbridge": true,
      "hsv": true,
      "prebuffering": false,
      "prebufferLength": 4,
      "videoConfig": {
        "source": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240 -max_muxing_queue_size 1024",
        "subSource": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",
        "stillImageSource": "-i http://[USERNAME]:[PASSWORD]@[LOCALIP]:25107/videostream.asf?user=[USERNAME]&pwd=[PASSWORD]&resolution=320x240",
        "rtspTransport": "tcp",
        "vcodec": "copy",
        "acodec": "libfdk_aac",
        "audio": true
      },
      "videoanalysis": {
        "active": false
      },
      "mqtt": {}
    },
    {
      "name": "Front of House",
      "manufacturer": "Insteon",
      "model": "2864-222",
      "serialNumber": "FIOCA1411002719",
      "excludeSwitch": false,
      "privacySwitch": true,
      "motion": true,
      "motionTimeout": 15,
      "unbridge": true,
      "hsv": true,
      "prebuffering": true,
      "forcePrebuffering": false,
      "prebufferLength": 4,
      "videoConfig": {
        "source": "-i rtsp://[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain -max_muxing_queue_size 1024",
        "subSource": "-i rtsp:[USERNAME]:[PASSWORD]@[LOCALIP]:25109/videoMain",
        "stillImageSource": "-i http://[LOCALIP]:25109/cgi-bin/CGIProxy.fcgi?usr=[USERNAME]&pwd=[PASSWORD]&cmd=snapPicture2",
        "rtspTransport": "tcp",
        "vcodec": "copy",
        "acodec": "libfdk_aac",
        "audio": true,
        "debug": true
      },
      "videoanalysis": {
        "active": false
      },
      "mqtt": {}
    }
  ]
}
leithma commented 2 years ago

Here is what I have... "rtspTransport": "tcp", "vcodec": "copy", "acodec": "libfdk_aac", "audio": false, "debug": true

This works with not audio but if I set autio to true it errors out

seydx commented 2 years ago

Here is what I have... "rtspTransport": "tcp", "vcodec": "copy", "acodec": "libfdk_aac", "audio": false, "debug": true

This works with not audio but if I set autio to true it errors out

Try the new config i posted above pls

leithma commented 2 years ago

@seydx Ok with your second config it is not erroring out, but with audio the stream starts in like 4 seconds and it is almost instant without audio. I do not know if that is expected.

seydx commented 2 years ago

@seydx Ok with your second config it is not erroring out, but with audio the stream starts in like 4 seconds and it is almost instant without audio. I do not know if that is expected.

Hm not really, do you have tried several times?

sometimes apple needs some time to trigger a „start“ event

leithma commented 2 years ago

Yea, I tried 3 or 4 times but all in a row.. I can let it run for 15 minutes or so and see if that helps HomeKit catchup.

seydx commented 2 years ago

Yea, I tried 3 or 4 times but all in a row.. I can let it run for 15 minutes or so and see if that helps HomeKit catchup.

Yeah thats a good idea

leithma commented 2 years ago

Just reporting back.. it is still slow with audio enabled..

6.98 seconds to get first frame

[1/15/2022, 4:41:10 PM] [CameraUI] Front of House: [info] Stream #0:1 -> #1:0 (pcm_mulaw (native) -> aac (libfdk_aac)) [1/15/2022, 4:41:10 PM] [CameraUI] Front of House: [info] Press [q] to stop, [?] for help [1/15/2022, 4:41:11 PM] [CameraUI] Front of House: [info] frame= 92 fps=0.0 q=-1.0 size= 779kB time=00:00:06.66 bitrate= 958.0kbits/s speed=11.7x
[1/15/2022, 4:41:11 PM] [CameraUI] Front of House: Getting the first frames took 6.989 seconds. [1/15/2022, 4:41:11 PM] [CameraUI] Front of House: [info] frame= 102 fps= 89 q=-1.0 size= 816kB time=00:00:07.21 bitrate= 927.4kbits/s speed=6.27x
[1/15/2022, 4:41:12 PM] [CameraUI] Front of House: [info] frame= 110 fps= 67 q=-1.0 size= 845kB time=00:00:07.72 bitrate= 896.1kbits/s speed=4.67x

vs.

.609 seconds for first frame with no audio

[1/15/2022, 4:43:38 PM] [CameraUI] Front of House: [info] Press [q] to stop, [?] for help [1/15/2022, 4:43:39 PM] [CameraUI] Front of House: [info] frame= 125 fps=0.0 q=-1.0 size= 1009kB time=00:00:08.24 bitrate=1002.1kbits/s speed=15.9x
[1/15/2022, 4:43:39 PM] [CameraUI] Front of House: Getting the first frames took 0.609 seconds. [1/15/2022, 4:43:39 PM] [CameraUI] Front of House: [info] frame= 133 fps=125 q=-1.0 size= 1044kB time=00:00:08.78 bitrate= 973.7kbits/s speed=8.23x
[1/15/2022, 4:43:40 PM] [CameraUI] Front of House: [info] frame= 141 fps= 88 q=-1.0 size= 1075kB time=00:00:09.31 bitrate= 945.7kbits/s speed=5.83x

All I did between these was flip the audio flag and restart.

seydx commented 2 years ago

Ah lol I had misunderstood. Yes, with audio it does take a bit longer, although 7 seconds is probably too long here. I assume this is due to the additional parameter that we have built into the source, maybe it is better if you reduce this from 1024 to 512?

leithma commented 2 years ago

got it.. I will try. Thanks for all the support!