frigate icon indicating copy to clipboard operation
frigate copied to clipboard

[Support]: rtsp basic auth with special characters doesnt work anymore

Open anttirokka opened this issue 3 years ago • 11 comments

Describe the problem you are having

Camera RTSP stream in 12. Beta special characters are not working in authentication

Version

0.12.0 Beta 2

Frigate config file

garage:
    ffmpeg:
      inputs:
        - path: rtsp://<user>:<password>@<ipaddr>:88/videoMain
          roles:
            - detect
            - record
        - path: rtsp://<user>:<password>@<ipaddr>:88/videoMain
          roles:
            - restream

Relevant log output

2023-01-09 15:06:26.535457018  [2023-01-09 15:06:26] frigate.video                  ERROR   : garden: Unable to read frames from ffmpeg process.
2023-01-09 15:06:26.535596596  [2023-01-09 15:06:26] frigate.video                  ERROR   : garden: ffmpeg process is not running. exiting capture thread...
2023-01-09 15:06:26.540134136  [2023-01-09 15:06:26] watchdog.garage                ERROR   : Ffmpeg process crashed unexpectedly for garage.
2023-01-09 15:06:26.540248282  [2023-01-09 15:06:26] watchdog.garage                ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
2023-01-09 15:06:26.540374616  [2023-01-09 15:06:26] ffmpeg.garage.detect           ERROR   : [rtsp @ 0x55a62c399f00] method DESCRIBE failed: 401 Unauthorized
2023-01-09 15:06:26.540376791  [2023-01-09 15:06:26] ffmpeg.garage.detect           ERROR   : rtsp://*:*@<ipaddr>/videoMain: Server returned 401 Unauthorize

FFprobe output from your camera

root@frigate-1:/data01/frigate# ffprobe rtsp://<user>:<pass>@<ipaddr>:88/videoMain
ffprobe version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  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
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65542
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65544
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65546
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65548
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65550
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65552
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65554
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65556
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65558
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65560
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65562
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65564
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65566
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65568
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65570
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65572
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65574
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65576
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65578
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65580
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65582
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65584
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65586
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65588
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65590
[h264 @ 0x5646bdbd2ac0] Missing reference picture, default is 65592
Input #0, rtsp, from 'rtsp://<user>:<pass>@<ipaddr>:88/videoMain':
  Metadata:
    title           : IP Camera Video
    comment         : videoMain
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 30 tbr, 90k tbn, 2108081.23 tbc
  Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s

Frigate stats

No response

Operating system

Other Linux

Install method

Docker Compose

Coral version

CPU (no coral)

Network connection

Wired

Camera make and model

opticam O6

Any other information that may be helpful

Upgrade from 11 -> to 12 beta and the rtsp auth doesnt seem to work anymore when password contains special characters

i have one camera without special character in password and that one works in 12 beta also

i have tried to input to frigate in plain text or encoded with % but either way i get the same error.

stream works from vlc and with ffmpeg and worked with frigate 11.

anttirokka avatar Jan 09 '23 13:01 anttirokka

Most users had issues with special characters in previous releases and that was fixed in 0.12. Which special characters are in the password?

NickM-27 avatar Jan 09 '23 13:01 NickM-27

tried couple, # %23 and ( %28

the # worked before.

i also noticed that the camera supports _ as special charactes, which doesnt require encoding. chanching the pw containing only _ as special char the frigate was able to connect.

anttirokka avatar Jan 09 '23 13:01 anttirokka

We handle the encoding for the password

https://github.com/blakeblackshear/frigate/blob/e79eab711afea62e9830973186600fe80b005de4/frigate/util.py#L730

we also have tests to ensure this is working as expected

https://github.com/blakeblackshear/frigate/blob/dev/frigate/test/test_camera_pw.py#L12

I am wondering if maybe your camera doesn't work with the % encoded characters considering that frigate 0.11 worked with special characters for you (and it was a common complaint that special characters didn't work previously)

NickM-27 avatar Jan 09 '23 14:01 NickM-27

I tested with with vlc and ffprobe these are the results. rtsp://<user>:password%23@<ipaddr>:88/videoMain <-works both vlc and ffprobe (also with frigate <12) rtsp://<user>:password#@<ipaddr>:88/videoMain <-doesnt work with vlc, ffprobe or frigate 12 (and if i remember correctly doesnt work either in some older frigate version) rtsp://<user>:password_@<ipaddr>:88/videoMain <- works with frigate 12 (changed the password to contain char which doesnt require encoding)

and also tested that the function in the code returns the %23.

print(urllib.parse.quote_plus("#")) %23

yes, the camera is "bulls**t" and definitely can do something odd and cause this. it is some rebranded camera and somewhat related to fosscam. link to local store, unfortunately in Finnish. https://www.verkkokauppa.com/fi/product/464940/Opticam-O6-PoE-valvontakamera-ulko-ja-sisakayttoon

anttirokka avatar Jan 09 '23 14:01 anttirokka

I added special characters to all my cameras passwords and they are working as expected. Will need to see what a good way to handle this edge case is.

NickM-27 avatar Jan 09 '23 16:01 NickM-27

yes, for me its not issue as such anymore, since i found the workaround for it. Let me know if you wish me to test something.

anttirokka avatar Jan 09 '23 19:01 anttirokka

I think it makes sense to wait and see how common this is before deciding to work on handling the edge case

NickM-27 avatar Jan 09 '23 22:01 NickM-27

I've had similar issues to this, however I'm not sure if it is connected. I upgraded to 0.12 and saw that it's better to use http streams instead of rtmp ones that I've been using on my Reolink RLC-410. All of my rtmp streams were setup in config.yaml like this:

  • path: rtmp://ip.add.res/bcs/channel0_sub.bcs?channel=0&stream=1&user=frigate&password={FRIGATE_PASSWORD} The frigate user was using a password that had this string of characters in it B@b%qEVf9gE* (there were letters before and after this and it has been changed now).

Now, the rtmp stream continue working fine with this password in 0.12.x, but the http streams will refuse to, until I change to a password with only letters and number.

frantathefranta avatar Jan 10 '23 03:01 frantathefranta

Now, the rtmp stream continue working fine with this password in 0.12.x, but the http streams will refuse to, until I change to a password with only letters and number.

I tested with my reolink cams with http and it worked as expected with special characters. Seems this might be decently camera specific

NickM-27 avatar Jan 10 '23 03:01 NickM-27

I understand the older type (which I have) is much more finnicky than the newer models, I'd not be surprised if it's a problem with only my model or a small selection.

frantathefranta avatar Jan 10 '23 03:01 frantathefranta

Interestingly I spent a while tearing my hair out yesterday with two new cams that Frigate wouldn't connect to, but VLC worked with fine. I was repeatedly using the "save config and restart" feature in Frigate while creating new users on the camera with no luck.

Eventually, I restarted the docker container and it seemed to suddenly start working. I had a brief look in the config code to see if there was any way old passwords could be getting cached but couldn't see anything obvious...can maybe try and recreate.

leccelecce avatar Jan 10 '23 10:01 leccelecce

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.

github-actions[bot] avatar Feb 10 '23 00:02 github-actions[bot]

TL;DR: Cameras were not working, thinking it being a password escape issue, but after leaving it erroring for a few minutes, Frigate was streaming correctly without issues. Anyone having this issue may just wait some time as another desperate workaround to try out.


Arriving from googling the issue of password escaping, as had the same issue of Frigate not loading the cameras but VLC working correctly.

Found that, indeed, one can just put the password as it is, un-escaped, with all the symbols on the config.yaml file and it will work.

But additionally, I found that somehow on the initial Docker container start of frigate, most of the times the cameras won't connect, logging the following:

2024-04-04 17:44:10.940367260  [tcp @ 0x3ddcf80] Port missing in uri
2024-04-04 17:44:10.940529997  [ERROR:[email protected]] global cap.cpp:164 open VIDEOIO(CV_IMAGES): raised OpenCV exception:
2024-04-04 17:44:10.940532422  
2024-04-04 17:44:10.940535996  OpenCV(4.7.0) /io/opencv/modules/videoio/src/cap_images.cpp:235: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: rtsp://User:REDACTED$p*@[email protected]:554/live in function 'icvExtractPattern'

Then more logs with

2024-04-04 17:44:31.399124894  [2024-04-04 17:44:31] watchdog.CAMERA-b        ERROR   : Ffmpeg process crashed unexpectedly for CAMERA-b.
2024-04-04 17:44:31.400055803  [2024-04-04 17:44:31] watchdog.CAMERA-b        ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
2024-04-04 17:44:31.401034753  [2024-04-04 17:44:31] ffmpeg.CAMERA-b.detect   ERROR   : [rtsp @ 0x557c6c99ae00] method DESCRIBE failed: 401 Unauthorized
2024-04-04 17:44:31.405098197  [2024-04-04 17:44:31] ffmpeg.CAMERA-b.detect   ERROR   : rtsp://*:*@192.168.1.2:554/live: Server returned 401 Unauthorized (authorization failed)

2024-04-04 17:44:31.436112758  [2024-04-04 17:44:31] frigate.video                  ERROR   : CAMERA-b: Unable to read frames from ffmpeg process.
2024-04-04 17:44:31.436381067  [2024-04-04 17:44:31] frigate.video                  ERROR   : CAMERA-b: ffmpeg process is not running. exiting capture thread...

So I decided to take a break, then come back after 20 mins or so, and the cameras are streaming on Frigate.

Tested with 2 cameras of the same model, and while Frigate kept throwing the error, I was able to successfully with VLC to one of them.

edmundo096 avatar Apr 05 '24 00:04 edmundo096