homebridge-camera-ffmpeg: Random video stream fails to start with "Socket error: Error"

Describe The Problem: Randomly through the week, I will not be able to stream the video for any of the cameras for a short duration (a few minutes).

I would see Socket error: Error in the logs for any of the cameras I would try to view.

I’ve ruled out issues with the network or RTSP streams because if I load the RTSP streams manually in VLC, they will all work. Also it would affect all of my cameras pointing to different streams.

After waiting a few minutes, I would be able to successfully view the stream without any other change.

Since the only that differs between my failed and successful attempts are the rtcpport or srtp ports which look randomized, and the fact that the error is “socket error”, I wonder if I’m running into some sort of port conflict with other apps/services running on my server.

To Reproduce:

  1. Randomly view a camera stream
  2. See error

Logs:

[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] Video stream requested: 1280 x 720, 30 fps, 299 kbps
[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] Starting video stream: 1280 x 720, 30 fps, 299 kbps (AAC-eld)
[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] Stream command: C:\Users\Long\AppData\Roaming\npm\node_modules\homebridge-camera-ffmpeg\node_modules\ffmpeg-for-homebridge\ffmpeg.exe -i rtsp://XXX@192.168.1.4:554/cam/realmonitor?channel=7&subtype=0 -an -sn -dn -codec:v libx264 -pix_fmt yuv420p -color_range mpeg -r 30 -f rawvideo -preset ultrafast -tune zerolatency -filter:v scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease,scale=trunc(iw/2)*2:trunc(ih/2)*2 -b:v 299k -payload_type 99 -ssrc 15449906 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params JF7l4xudkzUzmenEU8MH4eJmgwuLVj2ft/YqRqD5 srtp://192.168.1.141:58456?rtcpport=58456&pkt_size=1316 -vn -sn -dn -codec:a libfdk_aac -profile:a aac_eld -flags +global_header -f null -ar 16k -b:a 24k -ac 1 -payload_type 110 -ssrc 14230879 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params o4swsHRBqo9qSPrvFqJMis03SReauio6XlsJQWs+ srtp://192.168.1.141:64227?rtcpport=64227&pkt_size=188 -loglevel level+verbose -progress pipe:1
[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] Socket error: Error
[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] Stopped video stream.
[25/03/2021, 3:08:57 pm] [Camera FFmpeg] [Front] FFmpeg exited with code: null and signal: SIGKILL (Expected)
[25/03/2021, 3:09:06 pm] [homebridge-camera-ffmpeg] This plugin slows down Homebridge. The write handler for the characteristic 'Selected RTP Stream Configuration' on the accessory 'Front F9B7' didn't respond at all!. Please check that you properly call the callback! See https://git.io/JtMGR for more info.
[25/03/2021, 3:09:06 pm] [Camera FFmpeg] [Front] Stopped video stream.

Whereas a few seconds later it would work

[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] Video stream requested: 1280 x 720, 30 fps, 299 kbps
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] Starting video stream: 1280 x 720, 30 fps, 299 kbps (AAC-eld)
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] Stream command: C:\Users\Long\AppData\Roaming\npm\node_modules\homebridge-camera-ffmpeg\node_modules\ffmpeg-for-homebridge\ffmpeg.exe -i rtsp://XXX@192.168.1.4:554/cam/realmonitor?channel=7&subtype=0 -an -sn -dn -codec:v libx264 -pix_fmt yuv420p -color_range mpeg -r 30 -f rawvideo -preset ultrafast -tune zerolatency -filter:v scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease,scale=trunc(iw/2)*2:trunc(ih/2)*2 -b:v 299k -payload_type 99 -ssrc 6255934 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params pLbX84olcvQ2rYULpJp5d61a/LvAhGz1XNpPrU0g srtp://192.168.1.141:58252?rtcpport=58252&pkt_size=1316 -vn -sn -dn -codec:a libfdk_aac -profile:a aac_eld -flags +global_header -f null -ar 16k -b:a 24k -ac 1 -payload_type 110 -ssrc 2469502 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params eWXOJ2sWB2C1JZ2YMJ7SXyksedE3dekG1tlEkNTl srtp://192.168.1.141:49300?rtcpport=49300&pkt_size=188 -loglevel level+verbose -progress pipe:1
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info] ffmpeg version N-96777-gebee808595-ffmpeg-windows-build-helpers Copyright (c) 2000-2020 the FFmpeg developers
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   built with gcc 8.3.0 (GCC)
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   configuration: --pkg-config=pkg-config --pkg-config-flags=--static --extra-version=ffmpeg-windows-build-helpers --enable-version3 --disable-debug --disable-w32threads --arch=x86_64 --target-os=mingw32 --cross-prefix=/ffmpeg-windows-build-helpers/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --enable-libcaca --enable-gray --enable-libtesseract --enable-fontconfig --enable-gmp --enable-gnutls --enable-libass --enable-libbluray --enable-libbs2b --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libvorbis --enable-libwebp --enable-libzimg --enable-libzvbi --enable-libmysofa --enable-libopenjpeg --enable-libopenh264 --enable-liblensfun --enable-libvmaf --enable-libsrt --enable-demuxer=dash --enable-libxml2 --enable-opengl --enable-libdav1d --enable-libsvthevc --enable-libaom --enable-libvpx --enable-nvenc --enable-nvdec --extra-libs=-lharfbuzz --extra-libs=-lm --extra-libs=-lpthread --extra-cflags=-DLIBTWOLAME_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCACA_STATIC --enable-amf --enable-libmfx --enable-gpl --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable-librubberband --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxavs --enable-avresample --extra-cflags='-mtune=generic' --extra-cflags=-O3 --enable-static --disable-shared --prefix=/ffmpeg-windows-build-helpers/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-nonfree --enable-decklink --enable-libfdk-aac
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavutil      56. 41.100 / 56. 41.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavcodec     58. 70.100 / 58. 70.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavformat    58. 38.101 / 58. 38.101
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavdevice    58.  9.103 / 58.  9.103
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavfilter     7. 76.100 /  7. 76.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libavresample   4.  0.  0 /  4.  0.  0
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libswscale      5.  6.100 /  5.  6.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libswresample   3.  6.100 /  3.  6.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [info]   libpostproc    55.  6.100 / 55.  6.100
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [tcp @ 00000218bb6cdbc0] [verbose] Starting connection attempt to 192.168.1.4 port 554
[25/03/2021, 3:09:11 pm] [Camera FFmpeg] [Front] [tcp @ 00000218bb6cdbc0] [verbose] Successfully connected to 192.168.1.4 port 554

Homebridge Config:

        {
            "name": "Camera FFmpeg",
            "porthttp": 5005,
            "cameras": [
                {
                    "name": "Backyard",
                    "unbridge": true,
                    "videoConfig": {
                        "source": "-i rtsp://XXX@192.168.1.4:554/cam/realmonitor?channel=2&subtype=0",
                        "audio": true,
                        "debug": true
                    }
                },
                {
                    "name": "Front",
                    "unbridge": true,
                    "videoConfig": {
                        "source": "-i rtsp://XXX@192.168.1.4:554/cam/realmonitor?channel=7&subtype=0",
                        "audio": true,
                        "debug": true
                    }
                },
                {
                    "name": "Intercom",
                    "doorbell": true,
                    "unbridge": true,
                    "videoConfig": {
                        "source": "-i rtsp://192.168.1.3/h264_stream",
                        "stillImageSource": "-i http://192.168.1.3/api/camera/snapshot?width=1280&height=960",
                        "vcodec": "copy",
                        "audio": true,
                        "debug": true
                    }
                },
                // removed other entries for brevity
            ],
            "platform": "Camera-ffmpeg"
        },

Screenshots:

Environment:

  • Node.js Version: v14.14.0
  • NPM Version: 6.14.10
  • Homebridge Version: 1.3.3
  • Homebridge Camera FFmpeg Version: 3.1.2
  • Homebridge Config UI X Plugin Version: 4.40.0
  • Operating System: Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 33 (31 by maintainers)

Most upvoted comments

I lied, this should be fixed in 3.1.3

Figured I’d check in since stale bot popped back up. This fix should be released tomorrow.

I’d hold off on a PR, since I’m thinking it probably makes more sense to make a slightly deeper change than just whipping up a replacement. I’ll give it some thought, but I’m thinking something like along the lines of passing the open socket around instead of opening a socket, getting the port, closing it, and then reopening it.

And yea, I probably will PR their documentation, since the current wording isn’t accurate and causes confusion.

Well, that’s embarrassing.

In my defense, I believe I got that code from another developer. I guess I’ve just been lucky this whole time.

I’ll try to get that resolved in the next version, if I can find library that does what I actually need. I’ll look into portscanner to see if it fits the bill when I have a second.