Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live view not working #31

Closed
nxtByte opened this issue May 14, 2021 · 65 comments
Closed

Live view not working #31

nxtByte opened this issue May 14, 2021 · 65 comments
Labels

Comments

@nxtByte
Copy link

nxtByte commented May 14, 2021

Hey y'all,

today I tried setting up the proxy server. I have two Reolink cameras. I tried the command for the Reolink NVR and also the "normal" RTSP command as mentioned in the readme. When I look into the protect interface I can see snapshots in the "About" section. However, live view/streaming won't work. I can hear the live audio, but the video feed is stuck on one frame. I read through a bunch of different issues, tried setting the Reolink H264 Profile to "base" and some other tips I read, but nothing seems to fix my issue.
Do you have any ideas/suggestions? Can you please help me out?

//Edit: The BigBuckBunny (Readme) stream works flawless... it's just my cameras that won't work. Btw: resolution is 2560x1920. Does that make a difference? The g3's are 1920x1080 iirc

@keshavdv
Copy link
Owner

Can you share the specific Reolink camera you’re using? As you mentioned, I think this is identical to the other issue, but since I don’t have one myself, I can’t debug much on my own. Does recording work but not the live view?

@nxtByte
Copy link
Author

nxtByte commented May 16, 2021

I'm using the RLC-410-5MP with latest firmware. I even tried downgrading one version, because I thought maybe the new firmware was the problem. With both versions I had similar issues. Next thing I saw was that the small ReoLink couldn't handle the 3-4 simultaneous rtsp streams as the cpu usage went straight to 100% and stayed there. I then setup rtsp proxy servers. First off I tried the Live555Proxy. With that, it seemed, that the live view worked, but I couldn't tell, because maybe 200 pixels from the top were visible, the rest was just green artifacting. I thought maybe just an issue with Live555. So I setup a rtsp Proxy with ffmpeg and simple-rtsp-server. The proxying worked flawless, the stream worked in VLC on two different machines. When I entered the proxy stream into the unifi-cam-proxy, I had the same issue as when I connected directly to the cameras. I think, there might be some codec issues... I played around with ffmpeg, the rtsp server and some codecs, and after some time I got the same behaviour as with the Live555. However, when I got this behaviour, ffmpeg was full of errors because of the encoding. CPU of the host was only at around 10-20%, so that wasn't the issue. I can send you the commands I used for the proxy server and ffprobe output if you want later, just hit me up. I could even setup a VM to let you connect and test something if you want. I appreciate your project and your help. If I can do something of the above for you, just tell me.

@keshavdv
Copy link
Owner

The commands you ran plus ffprobe output of the original stream after you set the camera to the baseline profile for both the Clear and Fluent streams would be useful.

@nxtByte
Copy link
Author

nxtByte commented May 16, 2021

Yeah, sure. Here you go:
This is the command I used to proxy the livestream of the camera:
ffmpeg -stream_loop -1 -i rtsp://admin:secret@10.176.1.203 -c:v copy -f rtsp -rtsp_transport udp rtsp://localhost:8554/proxyStream (I also tried TCP as the protocol, didn't change anything)

I then used this command to start the unifi-cam-proxy:
unifi-cam-proxy --host 10.176.1.10 --mac 'AA:BB:CC:00:22:33' --cert client.pem --token secretToken rtsp -s rtsp://localhost:8554/proxyStream

This is the ffprobe output (baseline/clear):
ffprobe version 4.1.6-1~deb10u1 Copyright (c) 2007-2020 the FFmpeg developers built with gcc 8 (Debian 8.3.0-6) configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100 [rtsp @ 0x55c1f60f8100] max delay reached. need to consume packet [rtsp @ 0x55c1f60f8100] RTP: missed 2 packets Input #0, rtsp, from 'rtsp://admin:secret@10.176.1.203': Metadata: title : Session streamed by "preview" comment : Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (Baseline), yuv420p(progressive), 2560x1920, 30 tbr, 90k tbn, 180k tbc Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp

And the ffprobe output for baseline/fluent:
ffprobe version 4.1.6-1~deb10u1 Copyright (c) 2007-2020 the FFmpeg developers built with gcc 8 (Debian 8.3.0-6) configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100 Input #0, rtsp, from 'rtsp://admin:secret@10.176.1.203:554//h264Preview_01_sub': Metadata: title : Session streamed by "preview" comment : h264Preview_01_sub Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High), yuv420p(progressive), 640x480, 15 tbr, 90k tbn, 180k tbc Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp

@nxtByte
Copy link
Author

nxtByte commented May 16, 2021

UPDATE: After playing around with ffmpeg, the (rtsp) proxy server and the unifi-cam-proxy I finally got it to work with the fluent stream (max resolution 640x480).
I use this command to proxy my Reolink cam (that can't handle the 3-4 simultaneous streams):
ffmpeg -stream_loop -1 -i rtsp://admin:secret@10.176.1.203:554/h264Preview_01_sub -c:v h264 -preset:v ultrafast -f rtsp -rtsp_transport udp rtsp://localhost:8554/proxyStream (Notice the ultrafast preset; the reolink streams are already h264, but use a different preset I guess)

And then I use this command to start the unifi-cam-proxy:
unifi-cam-proxy --host 10.176.1.10 --mac 'AA:BB:CC:00:22:33' --cert client.pem --token secretToken rtsp -s rtsp://localhost:8554/proxyStream

After that, playback works fine. I think, that this could also work with the main (2560x1440 resolution) stream, but my mini-computer that I'm currently running the proxy on couldn't handle the (re-)encoding with this stream. I am going to try it out on a bigger system and post an update here. Sure, this solution is not optimal as it requires quite a bit of power to re-encode the stream, but hey, at least I can use my cameras with the UniFi protect system now.

//Update: this method also works with the main stream, but requires quite some CPU/GPU power to encode. Does it work? Yes. Would I recommend this method? No. I'll be testing a few different things to see, if I find any other workaround. If I find anything else, I'll post a new comment here.

@keshavdv
Copy link
Owner

Thanks for the output! Re-encoding into H264+AAC should make every camera compatible with Protect, but can be prohibitive without a GPU or a ton of compute power, especially for a 2k or 4k stream. If you can, do you mind sharing a raw video segment from the camera while it's set to the baseline profile? Running the following for 15-20s and ctrl-c'ing should dump a file that you can upload or email:

ffmpeg -i rtsp://... -acodec copy -vcodec copy output.mp4

@nxtByte
Copy link
Author

nxtByte commented May 16, 2021

No problem! I like to help :) I'll send you the raw files tomorrow, I'm not getting home until tomorrow morning (CEST).

@nxtByte nxtByte mentioned this issue May 16, 2021
@keshavdv
Copy link
Owner

keshavdv commented May 17, 2021

While not perfect, I think adding the following option to the unifi-cam-proxy call makes it work without re-encoding.

unifi-cam-proxy ... rtsp -s <your source> --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

The Reolink stream seem to not include VUI info in the h264 stream which makes the Protect side think the video stream is 0 FPS and discards it. This uses a bitstream filter to re-introduce this metadata with ffmpeg, but it'll need to match the actual original video parameters or it can throw things off. Assuming you have FPS set to 30 in the Reolink UI, 60000/1001 is correct, but otherwise you'll need to update this to match (15 fps -> 30000/1001).

Can you give this a go and see what happens?

Edit: you can probably reduce the cost by adding these options to the stream feeding rtsp-simple-server instead:

$ rtsp-simple-server &
$ ffmpeg -i rtsp://admin:secret@10.176.1.203:554/h264Preview_01_sub -c:v copy -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k -f rtsp -rtsp_transport udp rtsp://localhost:8554/proxyStream
$ unifi-cam-proxy --host 10.176.1.10 --mac 'AA:BB:CC:00:22:33' --cert client.pem --token secretToken rtsp -s rtsp://localhost:8554/proxyStream

@nxtByte
Copy link
Author

nxtByte commented May 17, 2021

Thank you for your reply. I just wanted to test it, but it didn't work because ffmpeg doesn't recognize the "h264_metadata" bitfilter. Which version are you using? Maybe I need to upgrade. I'm currently on 3.2.15-0+deb9u2 (latest from PPA)

@nxtByte
Copy link
Author

nxtByte commented May 17, 2021

I installed a newer ffmpeg version now, which fixed the problem with the unknown bitfilter. However, I now have the next problem :( When I try to run the ffmpeg command you stated above I get this error:
[h264_metadata @ 0x71e7fc0] low_delay_hrd_flag does not match inferred value: 1, but should be 0.
Do you know what's wrong here? I googled for this error, but didn't find any useful information.

@keshavdv
Copy link
Owner

Is that an error or warning? For me, I saw that but the stream still worked anyway.

@nxtByte
Copy link
Author

nxtByte commented May 17, 2021

Ah, sorry, I didn't post the full error. The error(s) displayed are below.
[h264_metadata @ 0x5b82500] low_delay_hrd_flag does not match inferred value: 1, but should be 0. [h264_metadata @ 0x5b82500] Failed to write unit 0 (type 7). [h264_metadata @ 0x5b82500] Failed to write extradata. Error initializing bitstream filter: h264_metadata Error initializing output stream 0:0 --
ffmpeg immediately closes after outputting them.

@acortelyou
Copy link
Contributor

Having this same issue on a honeywell/dahua dvr: recordings seems to work fine but the live view doesn't show up.

I tried the -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" fix and while the live view appeared it started getting corrupted very quickly with green artifacts.

I also saw the low_delay_hrd_flag does not match inferred value: 1, but should be 0. message but it appeared to just be a warning and aside from the green artifacts it was working.

Let me know if there's anything that would be useful for debugging.

@nxtByte
Copy link
Author

nxtByte commented May 18, 2021

Ah, sorry, I didn't post the full error. The error(s) displayed are below.
[h264_metadata @ 0x5b82500] low_delay_hrd_flag does not match inferred value: 1, but should be 0. [h264_metadata @ 0x5b82500] Failed to write unit 0 (type 7). [h264_metadata @ 0x5b82500] Failed to write extradata. Error initializing bitstream filter: h264_metadata Error initializing output stream 0:0 --
ffmpeg immediately closes after outputting them.

So, I tested your command with the h264_metadata injection on another system with Debian 10 and latest ffmpeg. Here it worked flawlessly. I still have the issue stated above with ffmpeg on Debian 9. But it seems to be just an issue on this specific system. I don't care, as long as it runs on my other system :D

So, long story short: With the injecting of the h264_metadata the playback and recording works flawlessly. Thank you very much for your help and this project. The metadata injecting is way more efficient then re-encoding, on my system injecting the metadata for 3 cameras requires around 10-15% CPU.
Also, if you share your PayPal, I am willing to make a donation to you for the nice work! :)

@nxtByte
Copy link
Author

nxtByte commented May 19, 2021

Having this same issue on a honeywell/dahua dvr: recordings seems to work fine but the live view doesn't show up.

I tried the -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" fix and while the live view appeared it started getting corrupted very quickly with green artifacts.

I also saw the low_delay_hrd_flag does not match inferred value: 1, but should be 0. message but it appeared to just be a warning and aside from the green artifacts it was working.

Let me know if there's anything that would be useful for debugging.

Did you look at the CPU usage of your system while trying this option? I had similar issues on a low-power device.

@acortelyou
Copy link
Contributor

Originally I tried the rtsp-simple-server method which was giving me the artifacts.

After switching to the --ffmpeg-args approach things got very usable!

I don't have audio so I replaced the audio related flags with -an.

FWIW I'm on debian 10 as well.

I'd say throw this workaround in the README and call it closed.

@nxtByte Switching to 1080p15 from 720p30 seemed to reduce the load significantly. I suspect it could be reduced even more if I could specify the low res rtsp substream for video2/video3 separately but that's a convo for a different issue.

@keshavdv I second the donation sentiment, perhaps you could take a look at the Github Sponsors platform or something like that.

@keshavdv
Copy link
Owner

I updated the readme with this workaround. If you'd like, we could create a Reolink (non-nvr) implementation that adds these ffmpeg args under the hood by default, but is also smarter about selecting the correct substream for the various video resolutions that Protect requests (see https://github.com/keshavdv/unifi-cam-proxy/blob/main/unifi/cams/lorex.py#L68-L70 as an example). Since I don't have one personally, I'd need somebody to share the correct urls to use.

@guido331
Copy link

guido331 commented May 20, 2021

I seem to be having this same issue with my FOSCAM cameras. I can see recordings but live view doesn't work. Interestingly, the Android App does show live view fine.

I'm running the following command:
unifi-cam-proxy --host 192.168.1.1 --mac 'AA:BB:CC:00:11:21' --ip 192.168.1.16 --cert client.pem --token UeWatBiknjPqGzJ3ZWQcz0in2Pm2IRUy rtsp -s rtsp://user:password@192.168.1.16:80/videoSub --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'
And seeing this:
INFO Spawning ffmpeg for video3 (HsZJ9t7gghqCCYeY): ffmpeg -nostdin -y -stimeout 15000000 -rtsp_transport tcp -i "rtsp://user:password@192.168.1.16:80/videoSub" -c:v copy -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k -metadata streamname=HsZJ9t7gghqCCYeY -f flv - | /usr/bin/python3 -m unifi.clock_sync | nc 192.168.1.1 7550

Any ideas?

//edit:
The bunny video works fine,
ffprobe output:

Input #0, rtsp, from 'rtsp://user:password@192.168.1.16:80/videoSub':
  Metadata:
    title           : IP Camera Video
    comment         : videoSub
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 90k tbr, 90k tbn, 3520886.88 tbc
    Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s

@keshavdv
Copy link
Owner

@guido331 Can you save a raw 15-30s clip from your camera with ffmpeg and share via email or other means?

@guido331
Copy link

Forgive my ignorance, I'm having trouble getting a file saved with Ubuntu:

ffmpeg -rtsp_transport tcp -i rtsp://user:password@192.168.1.16:80/videoSub abc.mp4 -acodec copy -vcodec copy -t 00:00:15:00

ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Trailing options were found on the commandline. Guessed Channel Layout for Input Stream #0.1 : mono Input #0, rtsp, from 'rtsp://user:password@192.168.1.16:80/videoSub': Metadata: title : IP Camera Video comment : videoSub Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 90k tbr, 90k tbn, 3520886.88 tbc Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s File 'abc.mp4' already exists. Overwrite ? [y/N] y Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (native)) Press [q] to stop, [?] for help [aac @ 0x55de46612840] Too many bits 8832.000000 > 6144 per frame requested, clamping to max [mp4 @ 0x55de465f9200] Frame rate very high for a muxer not efficiently supporting it. Please consider specifying a lower framerate, a different muxer or -vsync 2 [libx264 @ 0x55de46610480] using SAR=1/1 [libx264 @ 0x55de46610480] MB rate (324000000) > level limit (16711680) [libx264 @ 0x55de46610480] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64 [libx264 @ 0x55de46610480] profile High, level 6.2 [libx264 @ 0x55de46610480] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, mp4, to 'abc.mp4': Metadata: title : IP Camera Video comment : videoSub encoder : Lavf58.29.100 Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 90k fps, 90k tbn, 90k tbc Metadata: encoder : Lavc58.54.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s Metadata: encoder : Lavc58.54.100 aac More than 1000 frames duplicated ^C

@keshavdv
Copy link
Owner

I just usually do the following and press ctrl-c after 15-30s:

ffmpeg -rtsp_transport tcp -i rtsp://user:password@192.168.1.16:80/videoSub -acodec copy -vcodec copy out.mp4

@guido331
Copy link

Interesting, I'm beginning to suspect the stream from the camera itself:

[h264 @ 0x55e4898c9340] Missing reference picture, default is 65560 [h264 @ 0x55e4898c9340] Missing reference picture, default is 65562 Guessed Channel Layout for Input Stream #0.1 : mono Input #0, rtsp, from 'rtsp://user:password@192.168.1.16:80/videoSub': Metadata: title : IP Camera Video comment : videoSub Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 90k tbr, 90k tbn, 3520886.88 tbc Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s [mp4 @ 0x55e4898e9700] Could not find tag for codec pcm_mulaw in stream #1, codec not currently supported in container Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Last message repeated 1 times

@keshavdv
Copy link
Owner

Instead of ‘-acodec copy’, can you replace that with ‘-ar 32000 -ac 2 -codec:a aac -b:a 32k’ to force audio transcoding.

@guido331
Copy link

Thanks, I finally got the file saved. What's the best way to securely provide it to you? It's just the corner of my living room but still...

@keshavdv
Copy link
Owner

You can find my email attached to any of the commits in the repo if you’d like to send it over directly.

@guido331
Copy link

Sent, thanks for taking a look.

I'm happy to help if we want to test adding support for FOSCAM cameras

@guido331
Copy link

I've noticed motion detection doesn't work either, not sure if it's my camera or because live view doesn't work. I wasn't counting on smart detection to work but was at least hoping for motion detection. (the FOSCAM does motion detection natively)

Also, I can go back through the timelapse and view up to current but can't actually view the live video. (just stays on "Connecting to Live Feed").

Live view does work through the Android app though.

@keshavdv
Copy link
Owner

Can you try the following args?

‘’’
--ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=2206/100:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'
‘’’

With the RTSP implementation, neither motion or smart detections are supported because there is no standard implementation across cameras (perhaps we can build an ONVIF implementation). You’ll need to create a foscam specific implementation that interacts with the endpoints that are available to do this on your particular camera (see the Lorex implementation for motion examples or the Frigate implementation for smart detections).

@guido331
Copy link

That was it, live view is working with my FOSCAM cameras over RTSP. Thank you so much for the assistance.

@magnayn
Copy link

magnayn commented Jun 17, 2021

Forgive the drive-by; I'm having a similar issue with a (dirt cheap) Hiseeu device.

I'd assumed that it wasn't working because it hasn't got enough oomph to deliver >1 RTSP stream (which is true), so I've added an rtsp-simple-server proxy on the front (which seems to work, I can VLC from my laptop and the timelapse data still works).

However, 'live view' for me also doesn't work in the web app (but does in the iPhone protect app).

The (proxied) stream is 29.97fps 1920x1080p video, but has no audio. One thing I notice when trying 'live view' on the app is there's a lot of entries:

2021-06-17 12:05:28 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:28 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:28 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:28 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:29 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:29 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:29 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message
2021-06-17 12:05:29 unifi-cam-proxy RTSPCam[9541] INFO Processing [ChangeVideoSettings] message

ffprobe:

Input #0, rtsp, from 'rtsp://admin:@192.168.2.95/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp':
  Metadata:
    title           : RTSP Session
  Duration: N/A, start: 0.050000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 20 fps, 20 tbr, 90k tbn, 180k tbc

ffprobe (proxied):

Input #0, rtsp, from 'rtsp://192.168.2.104:8554/proxied':
  Metadata:
    title           : Stream
  Duration: N/A, start: -0.595178, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 20 fps, 20 tbr, 90k tbn, 180k tbc

Any ideas on things I could try?

@acortelyou
Copy link
Contributor

@magnayn Have you tried providing us with the --ffmpeg-args you are using?

@magnayn
Copy link

magnayn commented Jun 17, 2021

Ah, interesting - I missed that bit in the thread.

It's now working if I add

--ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=60000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

It is, however, taking quite a lot of CPU to do it (2x ffmpeg streams, ~30% CPU on each) ?

@keshavdv
Copy link
Owner

From your ffprobe output, the camera output is 20fps, not 29.97, so you should try tick_rate=40, but this won't do anything to help with CPU usage. In general, this is already using a bitstream filter, so there's already as minimal load as possible. What hardware are you running this on?

@magnayn
Copy link

magnayn commented Jun 18, 2021

Serves me right for reading the VLC information window and trusting it!

I think it's 30% of one vCPU if I'm reading it right, so it's probably liveable. It's in a proxmox LXC container.

I assume then that basically the reason the 'live' (web) view streams don't work is my camera isn't sending the right metadata about the stream (or it's in a format the protect app isn't happy with) ?

Either way, my cheapo camera seems to work a treat, thanks!

@saschawerner
Copy link

Ah, sorry, I didn't post the full error. The error(s) displayed are below.
[h264_metadata @ 0x5b82500] low_delay_hrd_flag does not match inferred value: 1, but should be 0. [h264_metadata @ 0x5b82500] Failed to write unit 0 (type 7). [h264_metadata @ 0x5b82500] Failed to write extradata. Error initializing bitstream filter: h264_metadata Error initializing output stream 0:0 --
ffmpeg immediately closes after outputting them.

So, I tested your command with the h264_metadata injection on another system with Debian 10 and latest ffmpeg. Here it worked flawlessly. I still have the issue stated above with ffmpeg on Debian 9. But it seems to be just an issue on this specific system. I don't care, as long as it runs on my other system :D

So, long story short: With the injecting of the h264_metadata the playback and recording works flawlessly. Thank you very much for your help and this project. The metadata injecting is way more efficient then re-encoding, on my system injecting the metadata for 3 cameras requires around 10-15% CPU.
Also, if you share your PayPal, I am willing to make a donation to you for the nice work! :)

I have the same issue on Debian 10 / ffmpeg version git-2021-07-16-cf12a47. Removing the :fixed_frame_rate_flag=1 from the args made 1 out of 4 cameras work however.

@keshavdv
Copy link
Owner

Can you share a paste of the ffmpeg output you see when this fails?

@saschawerner
Copy link

saschawerner commented Jul 19, 2021

pi@raspberrypi:~ $ ffmpeg -nostdin -y -timeout 15000000 -rtsp_transport tcp -i "rtsp://192.168.1.19:554/11" -c:v copy -vbsf "h264_metadata=tick_rate=50:fixed_frame_rate_flag=1" -ar 32000 -ac 1 -codec:a aac -b:a 32k -metadata streamname=MmRZhrkm7NfV7oMf -f flv -
ffmpeg version git-2021-07-16-cf12a47 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)
configuration: --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --extra-libs='-lpthread -lm -latomic' --arch=armel --enable-gmp --enable-gpl --enable-libaom --enable-libass --enable-libdav1d --enable-libdrm --enable-libfdk-aac --enable-libfreetype --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libssh --enable-libvorbis --enable-libvpx --enable-libzimg --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-mmal --enable-nonfree --enable-omx --enable-omx-rpi --enable-version3 --target-os=linux --enable-pthreads --enable-openssl --enable-hardcoded-tables
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 3.101 / 59. 3.101
libavformat 59. 4.100 / 59. 4.100
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.103 / 8. 0.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Input #0, rtsp, from 'rtsp://192.168.1.19:554/11':
Metadata:
title : 10
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn
Stream #0:1: Audio: adpcm_g726le, 8000 Hz, mono, s16, 16 kb/s
[h264_metadata @ 0x2d61240] low_delay_hrd_flag does not match inferred value: 1, but should be 0.
[h264_metadata @ 0x2d61240] Failed to write unit 0 (type 7).
[h264_metadata @ 0x2d61240] Failed to write extradata.
Error initializing bitstream filter: h264_metadata
Error initializing output stream 0:0 --
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (adpcm_g726le (g726le) -> aac (native))
Last message repeated 1 times

@saschawerner
Copy link

FFMpeg function

+#define infer(name, value) do { \

  •    if (current->name != (value)) { \
    
  •        av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
    
  •               "%s does not match inferred value: " \
    
  •               "%"PRId64", but should be %"PRId64".\n", \
    
  •               #name, (int64_t)current->name, (int64_t)(value)); \
    
  •    } \
    
  • } while (0)

@aboutte
Copy link

aboutte commented Jul 27, 2021

I am having the same issue where live view does not work and I can not view records from the UI.

  • Unifi NVR 3.10.13
  • TrendNET TV-IP315PI
  • ffprobe output:
$ ffprobe -i rtsp://tn01.camera.andyboutte.com/streaming/channels/101
ffprobe version 4.4 Copyright (c) 2007-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, rtsp, from 'rtsp://tn01.camera.andyboutte.com/streaming/channels/101':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 0.199667, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 2560x1440 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
  • command I am using to run unifi-cam-proxy:
docker run --rm -d -v "/home/aboutte/client.pem:/client.pem" keshavdv/unifi-cam-proxy unifi-cam-proxy \
	--verbose --ip 192.168.20.10 --host nvr.camera.andyboutte.com \
	--name "Barn Doors" --mac AD:AC:BD:55:55:54 --cert /client.pem \
	--model "UVC G3" --token sWPvNnqASekmGicS rtsp -s rtsp://tn01.camera.andyboutte.com/streaming/channels/101

Any feedback on what I can tweak so I can see records from the web UI? Live view and recordings do work from the iPhone app.

@stale
Copy link

stale bot commented Aug 26, 2021

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.

@stale stale bot added the stale label Aug 26, 2021
@stale stale bot closed this as completed Aug 29, 2021
@acortelyou
Copy link
Contributor

This issue has resurfaced for me after being forced to re-image my pi4 onto the latest rasperry pi os bullseye with ffmpeg 4.3.3.

Live view is broken without "--ffmpeg-args=-c:v copy -vbsf 'h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1' -an" but with it ffmpeg crashes with the following error:

[ffmpeg-20211223-194638.log](https://github.com/keshavdv/unifi-cam-proxy/files/7771142/ffmpeg-20211223-194638.log)
] low_delay_hrd_flag does not match inferred value: 1, but should be 0.
[h264_metadata @ 0x558813a280] Failed to write unit 0 (type 7).
[h264_metadata @ 0x558813a280] Failed to write extradata.
Error initializing bitstream filter: h264_metadata

I'm attaching the full ffmpeg report: ffmpeg-20211223-194638.log

I suspect this is related to #124 as it appears to be an issue with the 4.3 version of ffmpeg: the exact same command worked previously on 4.1.6-1~deb10u1+rpt1.

Using a 4.1.4 static binary fixes the issue.

@GhostlyCrowd
Copy link
Contributor

GhostlyCrowd commented Dec 23, 2021

This issue has resurfaced for me after being forced to re-image my pi4 onto the latest rasperry pi os bullseye with ffmpeg 4.3.3.

Live view is broken without "--ffmpeg-args=-c:v copy -vbsf 'h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1' -an" but with it ffmpeg crashes with the following error:

[ffmpeg-20211223-194638.log](https://github.com/keshavdv/unifi-cam-proxy/files/7771142/ffmpeg-20211223-194638.log)
] low_delay_hrd_flag does not match inferred value: 1, but should be 0.
[h264_metadata @ 0x558813a280] Failed to write unit 0 (type 7).
[h264_metadata @ 0x558813a280] Failed to write extradata.
Error initializing bitstream filter: h264_metadata

I'm attaching the full ffmpeg report: ffmpeg-20211223-194638.log

I suspect this is related to #124 as it appears to be an issue with the 4.3 version of ffmpeg: the exact same command worked previously on 4.1.6-1~deb10u1+rpt1.

Using a 4.1.4 static binary fixes the issue.

try

--ffmpeg-args '-c:v copy -bsf:v "h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

@acortelyou
Copy link
Contributor

try

--ffmpeg-args '-c:v copy -bsf:v "h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

No change to the error, ffmpeg 4.3.3 still crashes in the same way.
My particular camera has no audio stream so I use -an.

@GhostlyCrowd
Copy link
Contributor

try

--ffmpeg-args '-c:v copy -bsf:v "h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

No change to the error, ffmpeg 4.3.3 still crashes in the same way. My particular camera has no audio stream so I use -an.

i wonder if its actually a bug then.

-c:v copy -bsf:v "h264_metadata=tick_rate=30000/1001:fixed_frame_rate_flag=1"

was the magic sauce for me on ffmpeg 4.1.8 on debian buster

@keshavdv
Copy link
Owner

@acortelyou Do things start working if you remove the fixed_frame_rate_flag=1 part?

@acortelyou
Copy link
Contributor

@keshavdv ffmpeg doesn't error out if you omit fixed_frame_rate_flag=1 but in my testing the live view remained broken without it.

Currently I'm happily using ffmpeg 4.1.4, although I do still get a few frames of video corruption/green bars/blips every couple of minutes that I don't see when using VLC to view the stream.

@AliMickey
Copy link

AliMickey commented Jan 10, 2022

I am also running into the same issue, I can see snapshots being updated however live streaming does not work on either web/mobile app.

My NVR is some generic brand with analogue cameras being exposed over RTSP. These streams work perfectly with Home Assistant.

I have tried the suggested ffmpeg args in this thread, none of them change anything.

Main Command:
command: unifi-cam-proxy --host 10.0.0.1 --cert /client.pem --token <token> rtsp -s 'rtsp://user:pass@10.0.0.7:554/chID=1&streamType=main'

I'm running this in Docker. Based on the logs, the video streams keep being respawned after a couple of seconds.

Can provide additional info if required.
Thanks

EDIT:
It seems my password contained '!' which broke the command (Container wasnt outputting any logs). Changing the password leads to this error:

Input #0, rtsp, from 'rtsp://user:pass@10.0.0.7:554/chID=2&streamType=main':
  Metadata:
    title           : RTSP SESSION
  Duration: N/A, start: 0.100000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 2560x1936, 10 fps, 10 tbr, 90k tbn, 180k tbc
Output #0, flv, to 'pipe:':
  Metadata:
    title           : RTSP SESSION
    streamname      : jNzbaJvWRMP8Zu1M
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (High) ([7][0][0][0] / 0x0007), yuv420p(progressive), 2560x1936, q=2-31, 10 fps, 10 tbr, 1k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
[flv @ 0x55595839d380] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/app/unifi/clock_sync.py", line 167, in <module>
    main()
  File "/app/unifi/clock_sync.py", line 157, in main
    write(read_bytes(source, payload_size))
  File "/app/unifi/clock_sync.py", line 87, in write
    sys.stdout.buffer.write(data)
BrokenPipeError: [Errno 32] Broken pipe
av_interleaved_write_frame(): Broken pipe
[flv @ 0x55595839d380] Failed to update header with correct duration.
[flv @ 0x55595839d380] Failed to update header with correct filesize.
Error writing trailer of pipe:: Broken pipe
frame=   12 fps=0.0 q=-1.0 Lsize=     578kB time=00:00:01.00 bitrate=4731.2kbits/s speed= 139x
video:605kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

@olivernz
Copy link

olivernz commented Mar 3, 2022

So I am trying this with my UDM Pro and a vStarcam C29

This sort of works for me:
unifi-cam-proxy --host 192.168.1.1 --cert client.pem --token xxxxxxxxxxxxxxx rtsp -s 'rtsp://xxxxxx:xxxxxxx@192.168.xxx.xxx:10554/tcp/av0_0' --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=2206/100" -ar 32000 -ac 2 -codec:a aac -b:a 32k'

I have next to fluid video with a bit of lag of about 1sec. Framerate of the C29 is 7.5fps at high res 1080p (if it even has that).

But I keep getting this in the log: "Invalid data found when processing input". Then ffmpeg restarts and it does the same thing over again. By the looks there is minimal impact on video.

2022-03-03 02:36:33 test128 RTSPCam[5777] INFO Processing [ChangeVideoSettings] message
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
2022-03-03 02:36:33 test128 RTSPCam[5777] WARNING Previous ffmpeg process for video3 died.
2022-03-03 02:36:33 test128 RTSPCam[5777] INFO Spawning ffmpeg for video3 (oByUASO4Ddg5ZSyb): ffmpeg -nostdin -loglevel error -y -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -stimeout 15000000 -rtsp_transport tcp -i "rtsp://xxx:xxxx@192.168.xxx.xxx:10554/tcp/av0_0" -c:v copy -vbsf "h264_metadata=tick_rate=2206/100:fixed_frame_rate_flag=1" -an -metadata streamname=oByUASO4Ddg5ZSyb -f flv - | /usr/bin/python3 -m unifi.clock_sync | nc 192.168.xxx.1 7550
rtsp://xxx:xxx@192.168.xxx.xxx:10554/tcp/av0_0: Invalid data found when processing input
2022-03-03 02:36:40 test128 RTSPCam[5777] INFO Processing [NetworkStatus] message
2022-03-03 02:36:40 test128 RTSPCam[5777] INFO Processing [GetSystemStats] message
2022-03-03 02:36:45 test128 RTSPCam[5777] INFO Processing [GetRequest] message
2022-03-03 02:36:48 test128 RTSPCam[5777] INFO Processing [ChangeVideoSettings] message
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
....

Anyone have any idea what is going on there?
Thanks Oliver

@olivernz
Copy link

Dang, upgraded the UDM Pro to Protect v1.21.3. Now what was working before no longer does. The picture gets updated but no more streaming. Returning with the following error:

2022-03-16 21:52:03 test128 RTSPCam[1388] INFO Adopting with token [cccccccccccc] and mac [AABBCCDDEEFF] 2022-03-16 21:52:03 test128 RTSPCam[1388] INFO Processing [ubnt_avclient_hello] message 2022-03-16 21:52:03 test128 RTSPCam[1388] INFO Processing [ubnt_avclient_hello] message Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 167, in <module> main() File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 157, in main write(read_bytes(source, payload_size)) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 87, in write sys.stdout.buffer.write(data) BrokenPipeError: [Errno 32] Broken pipe Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> BrokenPipeError: [Errno 32] Broken pipe Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 167, in <module> main() File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 157, in main write(read_bytes(source, payload_size)) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 87, in write sys.stdout.buffer.write(data) BrokenPipeError: [Errno 32] Broken pipe Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> BrokenPipeError: [Errno 32] Broken pipe Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 167, in <module> main() File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 157, in main write(read_bytes(source, payload_size)) File "/usr/local/lib/python3.8/dist-packages/unifi/clock_sync.py", line 87, in write sys.stdout.buffer.write(data) BrokenPipeError: [Errno 32] Broken pipe Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> BrokenPipeError: [Errno 32] Broken pipe av_interleaved_write_frame(): Broken pipe Error writing trailer of pipe:: Broken pipe av_interleaved_write_frame(): Broken pipe Error writing trailer of pipe:: Broken pipe av_interleaved_write_frame(): Broken pipe Error writing trailer of pipe:: Broken pipe
The call is:
unifi-cam-proxy --host 192.168.1.1 --cert client.pem --token ccccccccc rtsp --rtsp-transport udp -s 'rtsp://user:pass@192.168.1.227:10554/udp/av0_0' --ffmpeg-args '-c:v copy -y -f segment -segment_time 5 -reset_timestamps 1 -strftime 1 -ar 8000 -ac 2 -codec:a aac -b:a 8k -vbsf "h264_metadata=tick_rate=2206/100"'

@chrisceska
Copy link

Just as FYI - in latest EA Protect 2.0.0-beta.5 - the /devices/add trick does not work anymore to get new adoption tokens.

@GlobiusAIM
Copy link

If the browser does not work real-time viewing and recording, but they are written. At the same time, everything is in order in the android application.
The controller requires an audio stream, so the -an key is invalid.
-ac 1 -codec:a aac -b:a 66k -ar 11025

@dcigir
Copy link

dcigir commented Feb 1, 2024

Hello, can somebody explain to me how could I use arguments in Docker on Synology NAS?
I have camera connected to protect, but I don't see stream, only snapshot. I have used this command in Docker:
“unifi-cam-proxy --host xxx.xxx.x.x --name Reolink --model ‘UVC G3’ --cert /client.pem --token xxxxxxxxxxxxxxxxxxxxxxxxx rtsp -s rtsp://xxxxx:xxxxxxx@xxx.xxx.x.xxx:554/h264Preview_01_main”
xxx is replacing my sensitive data.

I try to figure it out how to use this arguments bellow to maybe have stream in protect:
unifi-cam-proxy --mac '{unique MAC}' -H {NVR IP} -i {camera IP} -c /client.pem -t {Adoption token}
reolink
-u {username}
-p {password}
-s "main"
--ffmpeg-args='-c:v copy -bsf:v "h264_metadata=tick_rate=60000/1001" -ar 32000 -ac 1 -codec:a aac -b:a 32k'

Thanks in advance.
Denis

@mcaramb
Copy link

mcaramb commented Feb 1, 2024

yeah, this is a a problem caused by data being interrupted by a broken pipe. I'm thinking Unifi changed something again to thwart 3rd party streams. More in issue 344. #344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests