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

Unifi Protect RTSP camera problems #245

Closed lightbody closed 4 years ago

lightbody commented 5 years ago

I have mostly Unfi G3 cameras around the house, but also one Doorbird at my front door. I've found that the Doorbird streams flawlessly, but all of my Unifi cameras won't stream on my iOS devices. As I dug into it, one key difference I found is that the RTSP stream for my Doorbird is video only while the Unifi streams are audio + video.

Here are the debug logs for the working DoorBird:

Input #0, rtsp, from 'rtsp://xxx:xxx@doorbird.house:554/mpeg/media.amp': Metadata: title : RTSP/RTP stream from DoorBird comment : mpeg/media.amp Duration: N/A , start: 0.601000, bitrate: N/A Stream #0:0: Video: h264 (Main), yuvj420p(pc, progressive), 1280x720, 10 fps, 10 tbr, 90k tbn, 20 tbc

[swscaler @ 0x555a02dfdd00] deprecated pixel format used, make sure you did set range correctly

[libx264 @ 0x555a02e0b400] VBV maxrate unspecified, assuming CBR

[libx264 @ 0x555a02e0b400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2

[libx264 @ 0x555a02e0b400] profile High, level 2.2

Output #0, rtp, to 'srtp://10.0.1.27:50385?rtcpport=50385&localrtcpport=50385&pkt_size=1316': Metadata: title : RTSP/RTP stream from DoorBird comment : mpeg/media.amp encoder : Lavf57.56.101 Stream #0:0: Video: h264 (libx264), yuv420p, 640x360, q=-1--1, 132 kb/s, 10 fps, 90k tbn, 10 tbc Metadata: encoder : Lavc57.64.101 libx264 Side data: cpb: bitrate max/min/avg: 0/0/132000 buffer size: 132000 vbv_delay: -1 Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Press [q] to stop, [?] for help

frame= 4 fps=0.0 q=27.0 size= 9kB time=00:00:00.30 bitrate= 241.3kbits/s dup=0 drop=4 speed=0.588x

frame= 9 fps=8.9 q=25.0 size= 17kB time=00:00:00.80 bitrate= 174.7kbits/s dup=0 drop=4 speed=0.788x

And here are the debug logs for the broken Unifi camera:

Input #0, rtsp, from 'rtsp://10.0.1.127:7447/xxx': Metadata: title : F09FC2148091_1 Duration: N/A, start: 0.000000, bitrate: N/A

Stream #0:0: Audio: aac (LC), 11025 Hz, mono, fltp
Stream #0:1: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1024x576 [SAR 189:190 DAR 168:95], 15 fps, 15 tbr, 90k tbn, 30 tbc

Codec AVOption tune (Tune the encoding to a specific scenario) specified for output file #0 (srtp://10.0.1.27:55484?rtcpport=55484&localrtcpport=55484&pkt_size=1316) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (srtp://10.0.1.27:55484?rtcpport=55484&localrtcpport=55484&pkt_size=1316) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

Output #0, rtp, to 'srtp://10.0.1.27:55484?rtcpport=55484&localrtcpport=55484&pkt_size=1316': Metadata: title : F09FC2148091_1 encoder : Lavf57.56.101

Stream #0:0: Audio: pcm_mulaw, 11025 Hz, mono, s16, 88 kb/s
Metadata:
  encoder         : Lavc57.64.101 pcm_mulaw

Stream mapping: Stream #0:0 -> #0:0 (aac (native) -> pcm_mulaw (native)) Press [q] to stop, [?] for help size= 6kB time=00:00:00.55 bitrate= 89.5kbits/s speed=1.09x
size= 11kB time=00:00:01.02 bitrate= 89.4kbits/s speed=1.01x

Based on the debug logs, it seems like what is happening is that this homebridge-camera-ffmpeg assumes the video is at always stream 0 and audio is at stream 1. In the case of my DoorBird, which has no audio (not sure why!), it is indeed at stream 0. But with my Unifi cameras, stream 0 is audio and stream 1 is video. These logs seem to suggest that it's getting mixed up.

I'm an ffmpeg noob big time, but it seems like the hardcoding of "-map 0:0" in the source might be part of the problem?

lightbody commented 5 years ago

Update: I just monkey-patched "-map 0:0" to "-map 0:1" and my Unifi cameras started working. I'm not sure how to solve this generically, but at least it confirms some of the issue.

gbachs commented 5 years ago

I am having the exact same problem with my UniFi G3 cameras. What did you do exactly to make it work?

lightbody commented 5 years ago

I documented my workaround here: https://www.reddit.com/r/Ubiquiti/comments/ad8faw/comment/ee3sqxk?st=JR520QXV&sh=a99b8579

karlshea commented 5 years ago

I can confirm that also works for me.

karlshea commented 5 years ago

The change in #263 fixes this for me when I pass "mapvideo": "0:1", "mapaudio": "0:0" in the config file.

MitchJackson94 commented 4 years ago

My streams still not working I have added "mapvideo": "0:1", "mapaudio": "0:0" to my config.

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51826,
        "pin": "031-45-154"
    },
    "description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",
    "platforms": [
        {
            "platform": "Camera-ffmpeg",
            "cameras": [{
                "name": "Front Camera",
                "motion": true,
                "videoConfig": {
                    "source": "-rtsp_transport tcp -re -i rtsp://IP:7447/wdadawdw",
                    "stillImageSource": "-i http://IP/snap.jpeg",
                    "audio": true,
                    "maxStreams": 2,
                    "maxWidth": 1920,
                    "maxHeight": 1080,
                    "maxFPS": 15,
                    "mapvideo": "0:1",
                    "mapaudio": "0:0"
                }
            }]
        }
    ]
}
fhughes90 commented 4 years ago

I am in the same boat as MitchJackson94. The "mapvideo" and "mapaudio" are not fixing the live stream problem.

I get the still images every 12-15 secs fine but when I click on a camera in HomeKit, I get the error message "The camera is not responding". I do see this in the logs:

Screen Shot 2019-11-13 at 4 39 52 PM
MitchJackson94 commented 4 years ago

I have now got mine working I had to install ‘libfdk_acc’ manually as my ffmpeg did not include it

fhughes90 commented 4 years ago

do I just sudo apt-get install libfdk_aac

?

MitchJackson94 commented 4 years ago

Just had a look at my config and thinking back I actually could not get libfdk_aac installed what I did to get it working was change the audio codec to "acodec": "libopus" in the config.json I have video but no audio

fhughes90 commented 4 years ago

I tried your suggestion with adding "acodec" to the config.json and received an error on "unknown encoder: lib opus"

Screen Shot 2019-11-15 at 9 52 11 AM

Also, I notice (captured in the screenshot as well) srtp with my AppleTV IP address is "opening an output file". Is that natural with part of the HomeKit integration?

And one last question: The snapshots my cmaera-ffmpeg are getting from my cameras are at 320x240. Is that default or can this be changed? I don't have the "stillImagesource" in my config and wonder if that is why.

Thanks for your help

MitchJackson94 commented 4 years ago

What does your config look like? you could always try and install libfdk_aac it will also require you to build ffmpeg.

I think that's just the size that homekit uses the snapshot from the camera is 1920x1080.

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