Sunoo / homebridge-camera-ffmpeg

Homebridge Plugin Providing FFmpeg-based Camera Support
https://sunoo.github.io/homebridge-camera-ffmpeg/
Apache License 2.0
1.09k stars 225 forks source link

Unable to pull certain rstp stream reliably #1052

Closed UnbendableStraw closed 3 years ago

UnbendableStraw commented 3 years ago

I use a program called "happytime-rtsp-server" which turns my system into an rtsp server. I'm able to pull my webcam with rtsp://IP:554/videodevice flawlessly, however trying to pull the screen capture stream rtsp://IP:554/screenlive fails to get any thumbnails or stream video in the home app.

To repro, download happytime-rtsp-server, then pull your screen into the camera-ffmpeg plugin using rtsp://yourip:554/screenlive

The trouble-camera name in the config is "homebridge status"

Note I can pull the stream fine in vlc or my own cctv software. I've got quite a few cameras added through this camera-ffmpeg plugin and all the other ones stream on or off wifi really well!

Homebridge Config:

{
    "bridge": {
        "name": "Homebridge xx",
        "username": "xx",
        "port": xx, 
        "pin": "xx"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "auth": "form",
            "theme": "dark-mode",
            "tempUnits": "c",
            "lang": "auto",
            "platform": "config"
        },
        {
            "name": "Camera FFmpeg",
            "cameras": [
                {
                    "name": "Front Door",
                    "manufacturer": "Hikvision",
                    "model": "DS-2CD6332FWD-I",
                    "serialNumber": "x",
                    "firmwareRevision": "V5.4.5 build 170323",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://admin:password@192.168.1.64:554/Streaming/Channels/101/",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "copy",
                        "encoderOptions": "-preset ultrafast",
                        "audio": true,
                        "debug": false
                    }
                },
                {
                    "name": "Front PTZ",
                    "manufacturer": "Canon",
                    "model": "VB-S31D",
                    "serialNumber": "731263300071",
                    "firmwareRevision": "Ver. 1.1.1",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://system:password@127.0.0.1:8554/live?&serverip=192.168.1.240&serverport=6001&channelnumber=1&ssl=true",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "copy",
                        "encoderOptions": "-preset ultrafast"
                    }
                },
                {
                    "name": "Back Yard",
                    "manufacturer": "Axis",
                    "model": "P3225-LV MkII",
                    "serialNumber": "xx",
                    "firmwareRevision": "9.30.1",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://system:password@127.0.0.1:8554/live?&serverip=192.168.1.240&serverport=6001&channelnumber=3&ssl=true",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "libx264",
                        "videoFilter": "none",
                        "encoderOptions": "-preset ultrafast",
                        "debug": false
                    }
                },
                {
                    "name": "Living Room",
                    "manufacturer": "Dell",
                    "model": "Inspiron 3220 WebCam",
                    "serialNumber": "NA",
                    "firmwareRevision": "Ubuntu",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://192.168.1.247:554/videodevice",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "copy",
                        "encoderOptions": "-preset ultrafast",
                        "debug": false
                    }
                },
                {
                    "name": "Server Room",
                    "manufacturer": "Dynacolor",
                    "model": "NV223",
                    "serialNumber": "xx",
                    "firmwareRevision": "z120120420NSA",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://192.168.1.250/h264",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "copy",
                        "encoderOptions": "-preset ultrafast"
                    }
                },
                {
                    "name": "Homebridge Status",
                    "videoConfig": {
                        "source": "-fflags nobuffer -rtsp_transport tcp -i rtsp://192.168.1.247:554/screenlive",
                        "maxWidth": 0,
                        "maxHeight": 0,
                        "maxFPS": 0,
                        "maxBitrate": 0,
                        "forceMax": true,
                        "vcodec": "copy",
                        "encoderOptions": "-preset ultrafast",
                        "debug": true
                    }
                }
            ],
            "platform": "Camera-ffmpeg"
        },
        {
            "name": "Sun Lamp",
            "addCustomCharacteristics": true,
            "switchModels": [
                "HS100"
            ],
            "deviceTypes": [
                "plug",
                "bulb"
            ],
            "platform": "TplinkSmarthome"
        },
        {
            "platform": "cmdSwitch2",
            "name": "CMD Switch",
            "switches": [
                {
                    "name": "LRRTSP",
                    "on_cmd": "net start \"RTSP Restart\" && net stop \"RTSP Restart\"",
                    "off_cmd": "net start \"RTSP Restart\" && net stop \"RTSP Restart\"",
                    "state_cmd": "ping 192.168.1.247 | findstr Reply"
                }
            ]
        },
        {
            "platform": "cmdAccessory",
            "name": "CMD Accessory",
            "switches": [
                {
                    "name": "RTSP Server",
                    "on_cmd": "",
                    "off_cmd": "net start \"RTSP Restart\" && net stop \"RTSP Restart\"",
                    "state_cmd": "ping 192.168.1.247 | findstr Reply",
                    "polling": true,
                    "interval": 30,
                    "manufacturer": "Apple",
                    "type": "Switch"
                }
            ]
        }
    ],
    "disabledPlugins": [
        "homebridge-tplink-hs100-lightbulbs",
        "homebridge-cmd4",
        "homebridge-cmdswitch2"
    ]
}

Homebridge Console:

[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] Video stream requested: 1280 x 720, 30 fps, 299 kbps
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] Starting video stream: native x native, native fps, ??? kbps
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] Stream command: C:\Users\UnbendableStraw\AppData\Roaming\npm\node_modules\homebridge-camera-ffmpeg\node_modules\ffmpeg-for-homebridge\ffmpeg.exe -fflags nobuffer -rtsp_transport tcp -i rtsp://192.168.1.247:554/screenlive -an -sn -dn -codec:v copy -pix_fmt yuv420p -color_range mpeg -f rawvideo -preset ultrafast -payload_type 99 -ssrc 15077496 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params k9n/xIsLzYAJJPu/DgQiE8W36cTX4POGEMkdpuYK srtp://192.168.1.130:54121?rtcpport=54121&pkt_size=1316 -loglevel level+verbose
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info] ffmpeg version N-96777-gebee808595-ffmpeg-windows-build-helpers Copyright (c) 2000-2020 the FFmpeg developers
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   built with gcc 8.3.0 (GCC)
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [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
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavutil      56. 41.100 / 56. 41.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavcodec     58. 70.100 / 58. 70.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavformat    58. 38.101 / 58. 38.101
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavdevice    58.  9.103 / 58.  9.103
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavfilter     7. 76.100 /  7. 76.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libavresample   4.  0.  0 /  4.  0.  0
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libswscale      5.  6.100 /  5.  6.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libswresample   3.  6.100 /  3.  6.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [info]   libpostproc    55.  6.100 / 55.  6.100
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [tcp @ 0000024e6c396200] [verbose] Starting connection attempt to 192.168.1.247 port 554
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [tcp @ 0000024e6c396200] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [verbose] Successfully connected to 192.168.1.247 port 554
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [rtsp @ 0000024e6c393280] [verbose] SDP:
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] v=0
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] o=- 0 0 IN IP4 192.168.1.247
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] s=session
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] c=IN IP4 192.168.1.247
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] t=0 0
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=control:*
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=range:npt=0-
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] m=video 0 RTP/AVP 96
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=rtpmap:96 H264/90000
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=fmtp:96 packetization-mode=1;profile-level-id=000028;sprop-parameter-sets=Z01AKNoB4AiflhAAAAMAEAAAAwHo8YMq,aO88gA==
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=control:realvideo
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] m=application 0 RTP/AVP 98
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=rtpmap:98 vnd.onvif.metadata/90000
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] a=control:metadata
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [rtsp @ 0000024e6c393280] [verbose] setting jitter buffer size to 0
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] [rtsp @ 0000024e6c393280] [verbose] setting jitter buffer size to 0
[2/25/2021, 4:35:52 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:53 PM] [Camera FFmpeg] [Homebridge Status] [h264 @ 0000024e6c397880] [verbose] Reinit context to 1920x1088, pix_fmt: yuv420p
[2/25/2021, 4:35:53 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info] Input #0, rtsp, from 'rtsp://192.168.1.247:554/screenlive':
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]   Metadata:
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     title           : session
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]   Duration: N/A, start: 0.000000
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] , bitrate: N/A
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     Stream #0:0: Video: h264 (Main), 1 reference frame, yuv420p(progressive, left), 1920x1080 (1920x1088), 15 fps, 15 tbr, 90k tbn, 30 tbc
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     Stream #0:1: Data: none
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info] Output #0, rtp, to 'srtp://192.168.1.130:54121?rtcpport=54121&pkt_size=1316':
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]   Metadata:
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     title           : 
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] session
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     encoder         : Lavf58.38.101
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]     Stream #0:0: Video: h264 (Main), 1 reference frame, yuv420p(tv, progressive, left), 1920x1080 (0x0), q=2-31, 15 fps, 15 tbr, 90k tbn, 15 tbc
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info] Stream mapping:
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info]   Stream #0:0 -> #0:0 (copy)
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] [info] Press [q] to stop, [?] for help
[2/25/2021, 4:35:54 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:55 PM] [Camera FFmpeg] [Homebridge Status] [info] frame=    6 fps=0.0 q=-1.0 size=     435kB time=00:00:02.35 bitrate=1514.2kbits/s speed=4.57x    
[2/25/2021, 4:35:55 PM] [Camera FFmpeg] [Homebridge Status] [info] frame=   14 fps= 13 q=-1.0 size=     544kB time=00:00:02.88 bitrate=1543.2kbits/s speed=2.72x    
[2/25/2021, 4:35:56 PM] [Camera FFmpeg] [Homebridge Status] [info] frame=   22 fps= 14 q=-1.0 size=     960kB time=00:00:03.41 bitrate=2300.0kbits/s speed=2.15x    
[2/25/2021, 4:35:56 PM] [Camera FFmpeg] [Homebridge Status] [info] frame=   30 fps= 14 q=-1.0 size=    1042kB time=00:00:03.95 bitrate=2158.7kbits/s speed=1.86x    
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose] No more output streams to write to, finishing.
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [info] frame=   31 fps= 13 q=-1.0 Lsize=    1181kB time=00:00:04.04 bitrate=2389.4kbits/s speed=1.74x    
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [info] video:1168kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.094794%
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose] Input file #0 (rtsp://192.168.1.247:554/screenlive):
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose]   Input stream #0:0 (video): 33 packets read (1197804 bytes); 
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose]   Input stream #0:1 (data): 53 packets read (23055 bytes); 
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose]   Total: 86 packets (1220859 bytes) demuxed
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose] Output file #0 (srtp://192.168.1.130:54121?rtcpport=54121&pkt_size=1316):
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose]   Output stream #0:0 (video): 31 packets muxed (1195841 bytes); 
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [verbose]   Total: 31 packets (1195841 bytes) muxed
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] [AVIOContext @ 0000024e6d180bc0] [verbose] Statistics: 0 seeks, 947 writeouts
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] 
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] FFmpeg exited with code: 0 and signal: null (Error)
[2/25/2021, 4:35:57 PM] [Camera FFmpeg] [Homebridge Status] Stopped video stream.
UnbendableStraw commented 3 years ago

didnt think to try again on cellular. works fine on cellular. cant get it to work on wifi?

nevermind, it only worked for like 30 seconds : ( why is this the only camera I have issues with?

Sunoo commented 3 years ago

I’ve not seen the specific error mentioned in your logs before, but I’m asking around to see if anyone else has.

In the meantime, can you try transcoding instead of using copy, or try a lower bitrate? Sometimes HomeKit can be weirdly picky.

github-actions[bot] commented 3 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.