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

[Config support] ESP32 CAM with esphome doesn't work with go2rtc restream #292

Closed
Ginpachi98 opened this issue Mar 17, 2023 · 15 comments
Closed

Comments

@Ginpachi98
Copy link

Ginpachi98 commented Mar 17, 2023

I'm using frigate docker 12.0.9; two h264 cams with rtsp work very nice with radeonsi gpu and libva drivers, but mjpeg on ESP32 cam doesn't work with go2rtc. Didn't find any similar issues, hence I'm posting here. Here are some of the logs:

2023-03-17 23:59:18.369558373 192.168.1.8 - - [17/Mar/2023:23:59:18 +0100] "GET /api/stats HTTP/1.1" 200 2713 "-" "HomeAssistant/2023.3.3 aiohttp/3.8.4 Python/3.10" "-"
2023-03-17 23:59:16.557431724 [2023-03-17 23:59:16] frigate.video ERROR : doorbell: ffmpeg process is not running. exiting capture thread...
2023-03-17 23:59:16.557230493 [2023-03-17 23:59:16] frigate.video ERROR : doorbell: Unable to read frames from ffmpeg process.
2023-03-17 23:59:23.990223838 23:59:23.990 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:http:https://192.168.1.11:8080#video=h264#hardware
2023-03-17 23:59:31.447410550 [2023-03-17 23:59:31] watchdog.doorbell ERROR : The following ffmpeg logs include the last 100 lines prior to exit.
2023-03-17 23:59:31.447249488 [2023-03-17 23:59:31] watchdog.doorbell ERROR : Ffmpeg process crashed unexpectedly for doorbell.
2023-03-17 23:59:32.636345863 23:59:32.636 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:http:https://192.168.1.11:8080#video=h264#hardware
2023-03-17 23:59:19.432713606 [INFO] Starting go2rtc healthcheck service...
2023-03-17 23:59:24.645637756 23:59:24.645 WRN [rtsp] error="source 0 error: exec: exit status 1" stream=doorbell
2023-03-17 23:59:27.344773474 192.168.1.8 - - [17/Mar/2023:23:59:27 +0100] "GET /api/stats HTTP/1.1" 200 2680 "-" "HomeAssistant/2023.3.3 aiohttp/3.8.4 Python/3.10" "-"
2023-03-17 23:59:24.645518168 23:59:24.645 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:http:https://192.168.1.11:8080#video=h264#hardware
2023-03-17 23:59:31.447538891 [2023-03-17 23:59:31] ffmpeg.doorbell.detect ERROR : rtsp:https://127.0.0.1:8554/doorbell: Invalid data found when processing input
2023-03-17 23:59:31.991616710 23:59:31.991 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:http:https://192.168.1.11:8080#video=h264#hardware
2023-03-17 23:59:32.636552203 23:59:32.636 WRN [rtsp] error="source 0 error: exec: exit status 1" stream=doorbell
2023-03-17 23:59:32.639332405 [2023-03-17 23:59:32] frigate.video ERROR : doorbell: Unable to read frames from ffmpeg process.
2023-03-17 23:59:41.464302288 [2023-03-17 23:59:41] watchdog.doorbell ERROR : Ffmpeg process crashed unexpectedly for doorbell.
2023-03-17 23:59:41.464484290 [2023-03-17 23:59:41] watchdog.doorbell ERROR : The following ffmpeg logs include the last 100 lines prior to exit.
2023-03-17 23:59:32.639507744 [2023-03-17 23:59:32] frigate.video ERROR : doorbell: ffmpeg process is not running. exiting capture thread...
2023-03-17 23:59:36.351428697 192.168.1.8 - - [17/Mar/2023:23:59:36 +0100] "GET /api/stats HTTP/1.1" 200 2647 "-" "HomeAssistant/2023.3.3 aiohttp/3.8.4 Python/3.10" "-"

Here is config.yml

mqtt:
host: xx.xx.xx.xx
port: 1883
user: frigate
password: frigate
rtmp:
enabled: True

ffmpeg:
hwaccel_args: preset-vaapi

go2rtc:
streams:
doorbell: ffmpeg:http:https://192.168.1.11:8080#video=h264#hardware

cameras:
garaza:
ffmpeg:
inputs:
- path: rtsp:https://blabla
roles:
- rtmp
- record
record:
enabled: True
retain:
days: 7
mode: motion
detect:
enabled: False

stara_kuca:
ffmpeg:
inputs:
- path: rtsp:https://blabla
roles:
- rtmp
- record
detect:
enabled: False
record:
enabled: True
retain:
days: 7
mode: motion

doorbell:
ffmpeg:
inputs:
- path: rtsp:https://127.0.0.1:8554/doorbell
roles:
- record
rtmp:
enabled: False
detect:
enabled: False
record:
enabled: True
retain:
days: 7
mode: motion

Stream is working when I access it with IP address;

@NickM-27
Copy link
Contributor

You'll need to enable additional logs to see why it's failing. That being said, I'd suggest just having the http without ffmpeg: and have a separate ffmpeg stream with the camera name

go2rtc:
  streams:
    doorbell:
      - http:https://192.168.1.11:8080
      - ffmpeg:doorbell#video=h264#hardware

@Ginpachi98
Copy link
Author

I've now tried that format, still no stream. Added "logger: default:debug" to config, and this is doorbell related errors.

2023-03-18 00:14:04.075414640 [2023-03-18 00:14:04] frigate.video ERROR : doorbell: Unable to read frames from ffmpeg process.
2023-03-18 00:14:04.075584767 [2023-03-18 00:14:04] frigate.video ERROR : doorbell: ffmpeg process is not running. exiting capture thread...
2023-03-18 00:14:07.359346523 192.168.1.8 - - [18/Mar/2023:00:14:07 +0100] "GET /api/stats HTTP/1.1" 200 2681 "-" "HomeAssistant/2023.3.3 aiohttp/3.8.4 Python/3.10" "-"
2023-03-18 00:14:07.954382700 00:14:07.953 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:14:07.954669040 00:14:07.954 WRN [rtsp] error="codecs not match: JPEG" stream=doorbell
2023-03-18 00:14:07.954962709 00:14:07.954 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:14:08.953454769 [2023-03-18 00:14:08] watchdog.doorbell ERROR : Ffmpeg process crashed unexpectedly for doorbell.
2023-03-18 00:14:08.953772404 [2023-03-18 00:14:08] watchdog.doorbell ERROR : The following ffmpeg logs include the last 100 lines prior to exit.

@NickM-27
Copy link
Contributor

You'll need to set logs for exec to trace level

@Ginpachi98
Copy link
Author

I'd be happy to do that, unsure how? Is it docker env tag or?

Also, I've found this: blakeblackshear/frigate#4171
I'm not sure if this specific argument is being used as ffmpeg input argument for go2rtc or if it is even needed in this case, but figured could help.

@NickM-27
Copy link
Contributor

go2rtc:
  streams:
    ...
  log:
    exec: trace

@Ginpachi98
Copy link
Author

Got it! Thanks. Here is the log:

2023-03-18 00:28:12.516652053 [INFO] Preparing go2rtc config...
2023-03-18 00:28:12.832728669 [INFO] Starting go2rtc...
2023-03-18 00:28:12.925141994 00:28:12.923 INF go2rtc version 1.2.0 linux/amd64
2023-03-18 00:28:12.925149578 00:28:12.924 INF [api] listen addr=:1984
2023-03-18 00:28:12.925153325 00:28:12.924 INF [rtsp] listen addr=:8554
2023-03-18 00:28:12.925155983 00:28:12.924 INF [srtp] listen addr=:8443
2023-03-18 00:28:12.925158647 00:28:12.924 INF [webrtc] listen addr=:8555
2023-03-18 00:28:22.511081392 [INFO] Starting go2rtc healthcheck service...
2023-03-18 00:28:26.155231712 00:28:26.154 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:26.330613400 00:28:26.330 WRN github.com/AlexxIT/go2rtc/cmd/streams/producer.go:133 > error="unexpected EOF" url=http:https://192.168.1.11:8080
2023-03-18 00:28:31.203702196 Input #0, rtsp, from 'rtsp:https://localhost:8554/doorbell?video':
2023-03-18 00:28:31.203710383 Metadata:
2023-03-18 00:28:31.203712906 title : go2rtc/1.2.0
2023-03-18 00:28:31.203715200 Duration: N/A, start: 0.000000, bitrate: N/A
2023-03-18 00:28:31.203718014 Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1600x1200 [SAR 1:1 DAR 4:3], 4.17 tbr, 90k tbn
2023-03-18 00:28:31.241099716 Stream mapping:
2023-03-18 00:28:31.241111077 Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_vaapi))
2023-03-18 00:28:31.241113483 Press [q] to stop, [?] for help
2023-03-18 00:28:31.482118466 [mjpeg @ 0x555e4bfdbe00] No support for codec mjpeg profile 192.
2023-03-18 00:28:31.482128237 [mjpeg @ 0x555e4bfdbe00] Failed setup for format vaapi: hwaccel initialisation returned error.
2023-03-18 00:28:31.492127369 [swscaler @ 0x555e4c190a80] [swscaler @ 0x555e4c1aaa80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.492733706 [swscaler @ 0x555e4c190a80] [swscaler @ 0x555e4c327140] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.493358012 [swscaler @ 0x555e4c190a80] [swscaler @ 0x555e4c2c1280] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.493975679 [swscaler @ 0x555e4c190a80] [swscaler @ 0x555e4c2ff840] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.494613110 [swscaler @ 0x555e4c190a80] [swscaler @ 0x555e4c286d00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.496659547 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c355e00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.497166945 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c193040] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.497651330 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c330b00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.498186663 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c30a580] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.498671390 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c2b1cc0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.499514796 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c355e00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.500002955 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c190a80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.500482780 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c330b00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.500966463 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c30a580] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.501445965 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c2b1cc0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.502294077 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c355e00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.502784855 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c190a80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.503306212 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c330b00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.503790060 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c30a580] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.504262313 [swscaler @ 0x555e4c29bb40] [swscaler @ 0x555e4c2b1cc0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:28:31.517462713 [h264_vaapi @ 0x555e4bff8e80] No quality level set; using default (20).
2023-03-18 00:28:31.517472229 [h264_vaapi @ 0x555e4bff8e80] Driver does not support some wanted packed headers (wanted 0xd, found 0).
2023-03-18 00:28:31.517474416 [h264_vaapi @ 0x555e4bff8e80] Driver does not support packed sequence headers, but a global header is requested.
2023-03-18 00:28:31.517501463 [h264_vaapi @ 0x555e4bff8e80] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
2023-03-18 00:28:31.517504001 [h264_vaapi @ 0x555e4bff8e80] Hardware does not support encoding at size 1600x1200 (constraints: width 0-2048 height 0-1152).
2023-03-18 00:28:31.517905663 Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
2023-03-18 00:28:31.520961375 Conversion failed!
2023-03-18 00:28:31.530166695 00:28:31.529 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:31.530524248 00:28:31.530 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:36.646094611 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:28:36.647296661 00:28:36.647 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:36.647424408 00:28:36.647 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:41.766223853 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:28:41.767828308 00:28:41.767 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:41.768277465 00:28:41.767 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:41.768281623 00:28:41.768 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:28:41.768511564 00:28:41.768 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:28:46.892903201 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:28:46.894474615 00:28:46.894 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:46.894700860 00:28:46.894 WRN [rtsp] error="codecs not match: JPEG" stream=doorbell
2023-03-18 00:28:46.894707481 00:28:46.894 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:52.014104934 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:28:52.015901587 00:28:52.015 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:52.016142343 00:28:52.016 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:28:52.524179390 00:28:52.524 WRN [streams] json locked
2023-03-18 00:28:57.139596215 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:28:57.142072210 00:28:57.141 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:28:57.142079740 00:28:57.141 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:29:02.262098385 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:29:02.263478800 00:29:02.263 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:29:02.263489942 00:29:02.263 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:29:02.263492249 00:29:02.263 WRN [rtsp] error="codecs not match: JPEG" stream=doorbell
2023-03-18 00:29:07.380408432 rtsp:https://localhost:8554/doorbell?video: Invalid data found when processing input
2023-03-18 00:29:07.382387519 00:29:07.382 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:53 > error="exec: exit status 1" url=ffmpeg:doorbell#video=h264#hardware
2023-03-18 00:29:07.382542134 00:29:07.382 WRN [rtsp] error="codecs not match: JPEG" stream=doorbell
2023-03-18 00:29:07.382548662 00:29:07.382 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:29:07.382812409 00:29:07.382 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:29:07.383084262 00:29:07.382 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:29:07.383181020 00:29:07.383 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:29:07.383364486 00:29:07.383 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:29:07.383443993 00:29:07.383 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF

@NickM-27
Copy link
Contributor

NickM-27 commented Mar 17, 2023

Your GPU does not support an mjpeg profile with that resolution so you'll need to use it without hardware

@Ginpachi98
Copy link
Author

Ginpachi98 commented Mar 17, 2023

Yeah, I've tried it without hardware and it didn't work untill I've put 800x600 and 640x480. Now even gpu acceleration works, I have same usage as with H264 cams. Quality is quite bad and it's 5fps but just wanted to know if it would work.
Gpu is R9 270.
Here is current debug if it helps anyone:

2023-03-18 00:48:44.417552405 [INFO] Preparing go2rtc config...
2023-03-18 00:48:44.723260473 [INFO] Starting go2rtc...
2023-03-18 00:48:44.819735986 00:48:44.819 INF go2rtc version 1.2.0 linux/amd64
2023-03-18 00:48:44.821138452 00:48:44.820 INF [api] listen addr=:1984
2023-03-18 00:48:44.821145738 00:48:44.820 INF [rtsp] listen addr=:8554
2023-03-18 00:48:44.821152098 00:48:44.820 INF [srtp] listen addr=:8443
2023-03-18 00:48:44.821155473 00:48:44.820 INF [webrtc] listen addr=:8555
2023-03-18 00:48:54.421966936 [INFO] Starting go2rtc healthcheck service...
2023-03-18 00:48:57.710611109 00:48:57.710 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:48:57.885506595 00:48:57.885 WRN github.com/AlexxIT/go2rtc/cmd/streams/producer.go:133 > error="unexpected EOF" url=http:https://192.168.1.11:8080
2023-03-18 00:49:00.896273783 Input #0, rtsp, from 'rtsp:https://localhost:8554/doorbell?video':
2023-03-18 00:49:00.896282036 Metadata:
2023-03-18 00:49:00.896284493 title : go2rtc/1.2.0
2023-03-18 00:49:00.896317877 Duration: N/A, start: 0.000000, bitrate: N/A
2023-03-18 00:49:00.896332300 Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 640x480 [SAR 1:1 DAR 4:3], 90k tbr, 90k tbn
2023-03-18 00:49:00.939041170 Stream mapping:
2023-03-18 00:49:00.939050971 Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_vaapi))
2023-03-18 00:49:00.939053332 Press [q] to stop, [?] for help
2023-03-18 00:49:01.106760024 [mjpeg @ 0x564abefa70c0] No support for codec mjpeg profile 192.
2023-03-18 00:49:01.106769579 [mjpeg @ 0x564abefa70c0] Failed setup for format vaapi: hwaccel initialisation returned error.
2023-03-18 00:49:01.110226065 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf196180] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.110616357 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1af7c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.110970142 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1d0f80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.111380566 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1f2740] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.111787598 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf213f00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.113777722 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf196180] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.114168836 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1a6380] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.114580772 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1c6c00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.114926595 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf208740] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.115316578 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1e6f80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.116070515 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf196180] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.116466762 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1e6f80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.116796073 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1a6380] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.117168575 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1c6c00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.117505782 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf208740] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.118239695 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf196180] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.118577146 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1a6380] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.118961870 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1e6f80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.119300913 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf1c6c00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.119665288 [swscaler @ 0x564abf14d5c0] [swscaler @ 0x564abf2096c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:01.127958710 [rtsp @ 0x564abefa7b80] Frame rate very high for a muxer not efficiently supporting it.
2023-03-18 00:49:01.127962847 Please consider specifying a lower framerate, a different muxer or setting vsync/fps_mode to vfr
2023-03-18 00:49:01.128332735 [h264_vaapi @ 0x564abefacb80] No quality level set; using default (20).
2023-03-18 00:49:01.128375479 [h264_vaapi @ 0x564abefacb80] Driver does not support some wanted packed headers (wanted 0xd, found 0).
2023-03-18 00:49:01.128378974 [h264_vaapi @ 0x564abefacb80] Driver does not support packed sequence headers, but a global header is requested.
2023-03-18 00:49:01.128382079 [h264_vaapi @ 0x564abefacb80] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
2023-03-18 00:49:01.171138719 Output #0, rtsp, to 'rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b':
2023-03-18 00:49:01.171149549 Metadata:
2023-03-18 00:49:01.171152297 title : 00:49:01.171 DBG [exec] run launch=3.460479364s
2023-03-18 00:49:01.171154268 go2rtc/1.2.0
2023-03-18 00:49:01.171156376 encoder : Lavf59.27.100
2023-03-18 00:49:01.171263277 Stream #0:0: Video: h264 (High), vaapi(tv, bt470bg/unknown/unknown, progressive), 640x480 [SAR 1:1 DAR 4:3], q=2-31, 90k fps, 90k tbn
2023-03-18 00:49:01.171266241 Metadata:
2023-03-18 00:49:01.171268536 encoder : Lavc59.37.100 h264_vaapi
2023-03-18 00:49:01.171473142 00:49:01.171 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:221 > error=EOF
2023-03-18 00:49:01.858698104 av_interleaved_write_frame(): Broken pipe
2023-03-18 00:49:01.858828368 frame= 1 fps=0.0 q=-0.0 size=N/A time=00:00:03.36 bitrate=N/A speed=N/A
frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:03.36 bitrate=N/A speed=3.65x
2023-03-18 00:49:01.858888322 video:7kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
2023-03-18 00:49:01.862668162 Conversion failed!
2023-03-18 00:49:01.869830995 00:49:01.869 TRC [exec] close url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:49:06.264893819 00:49:06.264 DBG [exec] run url="exec:ffmpeg -hide_banner -hwaccel vaapi -hwaccel_output_format vaapi -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp:https://localhost:8554/doorbell?video -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -an -vf format=vaapi|nv12,hwupload -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b"
2023-03-18 00:49:10.562474377 Input #0, rtsp, from 'rtsp:https://localhost:8554/doorbell?video':
2023-03-18 00:49:10.562482765 Metadata:
2023-03-18 00:49:10.562485294 title : go2rtc/1.2.0
2023-03-18 00:49:10.562552226 Duration: N/A, start: 0.000000, bitrate: N/A
2023-03-18 00:49:10.562790513 Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 640x480 [SAR 1:1 DAR 4:3], 23.67 tbr, 90k tbn
2023-03-18 00:49:10.605696218 Stream mapping:
2023-03-18 00:49:10.605705818 Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_vaapi))
2023-03-18 00:49:10.605708200 Press [q] to stop, [?] for help
2023-03-18 00:49:10.772603401 [mjpeg @ 0x55666d8280c0] No support for codec mjpeg profile 192.
2023-03-18 00:49:10.772611497 [mjpeg @ 0x55666d8280c0] Failed setup for format vaapi: hwaccel initialisation returned error.
2023-03-18 00:49:10.776029741 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da171c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.776439094 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da37280] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.776793125 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da53b00] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.777202284 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da750c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.777616185 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da96880] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.779501179 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da171c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.779825711 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da8b0c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.780149404 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da69900] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.780467681 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da37280] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.780788833 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da4b840] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.781433503 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da171c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.781758165 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da69900] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.782089945 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da8b0c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.782411979 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da37280] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.782726584 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da4cb80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.784893517 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da171c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.785212335 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da69900] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.785594074 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da8b0c0] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.785910842 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da37280] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.786297057 [swscaler @ 0x55666d9ce600] [swscaler @ 0x55666da4cb80] deprecated pixel format used, make sure you did set range correctly
2023-03-18 00:49:10.789923281 [h264_vaapi @ 0x55666d82db80] No quality level set; using default (20).
2023-03-18 00:49:10.789945738 [h264_vaapi @ 0x55666d82db80] Driver does not support some wanted packed headers (wanted 0xd, found 0).
2023-03-18 00:49:10.789949239 [h264_vaapi @ 0x55666d82db80] Driver does not support packed sequence headers, but a global header is requested.
2023-03-18 00:49:10.789952395 [h264_vaapi @ 0x55666d82db80] No global header will be written: this may result in a stream which is not usable for some purposes (e.g. not muxable to some containers).
2023-03-18 00:49:10.835096070 00:49:10.834 DBG [exec] run launch=4.570130558s
2023-03-18 00:49:10.835100258 Output #0, rtsp, to 'rtsp:https://localhost:8554/d69c1eea156ca8f77a4b9c8e7b211d6b':
2023-03-18 00:49:10.835102520 Metadata:
2023-03-18 00:49:10.835122812 title : go2rtc/1.2.0
2023-03-18 00:49:10.835125500 encoder : Lavf59.27.100
2023-03-18 00:49:10.835297958 Stream #0:0: Video: h264 (High), vaapi(tv, bt470bg/unknown/unknown, progressive), 640x480 [SAR 1:1 DAR 4:3], q=2-31, 23.67 fps, 90k tbn
2023-03-18 00:49:10.835314188 Metadata:
2023-03-18 00:49:10.835322345 encoder : Lavc59.37.100 h264_vaapi

Thank you, that log tracing sure is usefull :D

@JohnNeville
Copy link

@Ginpachi98 You wouldn't happen to be able to post your configs would you? I am trying to get the same thing working and I can't figure out how you solved this.

@Ginpachi98
Copy link
Author

Ginpachi98 commented Apr 14, 2023

mqtt:
  host: xxxxxxx
  port: 1883
  user: frigate
  password: frigate
rtmp:
  enabled: True


ffmpeg:
  hwaccel_args: preset-vaapi

go2rtc:
  streams:
    garaza:
      - rtsp:https://xxxxxxxxxx
      - ffmpeg:garaza#video=h264#hardware
    stara_kuca:
      - rtsp:https://xxxxxxxxxxx
      - ffmpeg:stara_kuca#video=h264#hardware
    kuhinja:
      - http:https://192.168.1.225:8080/video
      - ffmpeg:kuhinja#video=h264#hardware
    doorbell:
      - http:https://192.168.1.11:8080
      - ffmpeg:doorbell#video=h264#hardware
  log:
    exec: trace


cameras:
  garaza:
    ffmpeg:
      inputs:
        - path: rtsp:https://127.0.0.1:8554/garaza
          roles:
            - rtmp
            - record
    record:
      enabled: True
      retain:
        days: 7
        mode: motion
    detect:
      enabled: False

  stara_kuca:
    ffmpeg:
      inputs:
        - path: rtsp:https://127.0.0.1:8554/stara_kuca
          roles:
            - rtmp
            - record
    detect:
      enabled: False
    record:
      enabled: True
      retain:
        days: 7
        mode: motion

  kuhinja:
    ffmpeg:
      inputs:
        - path: rtsp:https://127.0.0.1:8554/kuhinja
          roles:
            - record
    rtmp:
      enabled: False
    detect:
      enabled: False
    record:
      enabled: True
      retain:
        days: 7
        mode: motion


  doorbell:
    ffmpeg:
      inputs:
        - path: rtsp:https://127.0.0.1:8554/doorbell
          roles:
            - record
    rtmp:
      enabled: False
    detect:
      enabled: False
    record:
      enabled: True
      retain:
        days: 7
        mode: motion

The idea is that esp32 cam has 800x600; important esphome yaml part:

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  vertical_flip: False
  horizontal_mirror: False
  resolution: 800x600
  jpeg_quality: 10
  name: Doorcam
  max_framerate: 5 fps
  
  also:
 
esp32_camera_web_server:
  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot

and docker:

  frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: always
    image: "ghcr.io/blakeblackshear/frigate:stable"
    shm_size: "128mb" # update for your cameras based on calculation above
    devices:
      - /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - frigate_config:/config/
      - /srv/dev-disk-by-uuid-3c180d4d-234c-4164-9544-02832d2d5415/records:/media/frigate
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "5000:5000"
      - "1935:1935" # RTMP feeds
    environment:
      FRIGATE_RTSP_PASSWORD: "password"
      LIBVA_DRIVER_NAME: radeonsi

@erkexzcx
Copy link

erkexzcx commented Sep 15, 2023

EDIT: Still does not work properly. I don't know, I am no longer interested wasting more time on ESPCAMs :/


Spent few hours troubleshooting why ESP32-CAM from AliExpress does not work properly with Frigate (go2rtc).

It's simple - turns out it must not go beyond 640x480 resolution at 5fps.


When you go to ESPHome dashboard, open wireless logs and find this:

[18:32:56][D][esp32_camera:196]: Got Image: len=15898
[18:32:56][D][esp32_camera_web_server:198]: MJPG: 15898B 209ms (4.8fps)
[18:32:56][D][esp32_camera:196]: Got Image: len=15917
[18:32:57][D][esp32_camera_web_server:198]: MJPG: 15917B 207ms (4.8fps)
[18:32:57][D][esp32_camera:196]: Got Image: len=15874
[18:32:57][D][esp32_camera_web_server:198]: MJPG: 15874B 206ms (4.9fps)
[18:32:57][D][esp32_camera:196]: Got Image: len=15994
[18:32:57][D][esp32_camera_web_server:198]: MJPG: 15994B 206ms (4.9fps)
[18:32:57][D][esp32_camera:196]: Got Image: len=15889
[18:32:57][D][esp32_camera_web_server:198]: MJPG: 15889B 211ms (4.7fps)

As you can see, it's close enough to 5fps, which is great - camera is able to catch up with requested framerate. If you find yourself watching it be like 2-3fps - that means it cannot produce frames on time and therefore go2rtc hungs/crashes because stream arrives out of order... Restarting go2rtc fixes it for a few seconds and freezes again. It's not stable and you have to reduce throughput of the stream - either reduce resolution, fps or both.


Here is my config for those who are interesting. Intel nuc, using vaapi hw accel.

Frigate part:

go2rtc:
  streams:
    cam01:
      - "http:https://123.123.123.123:8080/"
      - "ffmpeg:cam01#video=h264#hardware"

ESPHome part:

esp32_camera_web_server:
  - port: 8080
    mode: stream

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  name: espcam01
  resolution: 640x480
  max_framerate: 5fps

@erkexzcx
Copy link

erkexzcx commented Oct 12, 2023

After playing around a bit more, I've achieved "something-works" kind of state.

ESPHome config part. I am using almost max resolution with 1fps (that's my use case). Also pay attention to jpeg_quality: 15 - it tends to crash on 10 (max value) and combined with high resolution - probably not enough resources. Anyway, below config seems to kind-of'ish work:

esp32_camera_web_server:
  - port: 8080
    mode: stream

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  name: espcam01
  resolution: 2560x1440
  max_framerate: 1fps
  jpeg_quality: 15
  vertical_flip: False
  horizontal_mirror: False

Frigate config. Note those #raw=... options - they are needed. ESPCAM stream is 💩, so we instruct ffmpeg to handle a 💩-tier stream. Some options are even self-explanatory, such as discardcorrupt:

go2rtc:
  streams:
    cam01:
      - "http:https://123.123.123.123:8080"
      - "ffmpeg:cam01#video=h264#hardware#raw=-avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1" 
  webrtc:
    candidates:
      - 123.123.123.123:8555
      - example.com:8555
      - stun:8555

cameras:
  cam01:
    ffmpeg:
      inputs:
        - path: rtsp:https://127.0.0.1:8554/cam01
          roles: [detect]

I would say - give it some time. If still does not work - restart something. It's a hit or miss with ESPCAM, but once it works - it works without issues.

@erkexzcx
Copy link

After more and more digging, I've came to this conclusion: ESP32 CAM stream is very unstable and no matter how hard you try - recording it is going to be almost impossible. I think that's the problem with all mjpeg streams.

As an alternative, it is possible to (fully successfully) use ESP32 CAM without record role in Frigate:

go2rtc:
  streams:
    cam01:
      - "http:https://123.123.123.123:8080"

cameras:
  cam01:
    ffmpeg:
      inputs:
        - path: http:https://127.0.0.1:1984/api/stream.mjpeg?src=cam01
          roles: [detect]
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -c:v mjpeg

# Hardware accel disabled, otherwise bottom half of the mjpeg stream is green
# ffmpeg:
#   hwaccel_args: preset-vaapi

In HomeAssistant Frigate card use this - directly from go2rtc which re-streams raw mjpeg stream:

type: custom:frigate-card
cameras:
  - camera_entity: camera.cam01
    live_provider: go2rtc
    id: cam01
    title: cam01
    go2rtc:
      modes:
        - mjpeg
      stream: cam01

In ESPHome somehow this started to work just fine too!

  resolution: 2560x1440
  max_framerate: 1fps
  jpeg_quality: 10

@erkexzcx
Copy link

So I guess this is my last message with conclusions... 🤷

Do not record ESP32 CAM stream

Everything seem to work fine with go2rtc and Frigate simply if you don't enable record on ESP32 CAM stream. Stream is very unstable, no matter what you do. Or it might work if you (a) have a superb great WiFi and (b) enable low resolution with low FPS value. Something like 800x600 might be a start. The key problem is that if you want to record ESP32 CAM stream - you have to convert it from MJPEG stream to H264 stream and go2rtc/frigate/ffmepg fails to perform this against such unstable stream. Note that detection and re-stream of mjpeg stream (using go2rtc) works perfectly, but Frigate (and go2rtc) "shits itself" when it tries to record it and it causes all sorts of problems (such as camera stream is not visible in webui).

Here is my Frigate config that works great!

go2rtc:
  streams:
    cam01:
      - "http:https://123.123.123.123:8080"

cameras:
  cam01:
    ffmpeg:
      inputs:
        - path: http:https://127.0.0.1:1984/api/stream.mjpeg?src=cam01
          roles: [detect]
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -c:v mjpeg

Disable "auto" for aec and agc to improve stability

What if I tell you that you can enable max resolution at stable 1 FPS? Well, the key factors that causes such instabilities are camera's automations, called aec and agc. When these are set to auto - camera has to re-calculate average lighting and exposure to compensate it and adjust camera sensitivity accordingly. This is resource intensive and really breaks the camera (probably causes restart = crash) when you crank up the resolution to it's maximum. Here is my config, works superb great for the past day and not a single issue on my terrible wifi connecion:

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  name: espcam01
  resolution: 2560x1440
  max_framerate: 1fps
  jpeg_quality: 10
  vertical_flip: False
  horizontal_mirror: False
  aec_mode: manual
  agc_mode: manual
  wb_mode: home
  aec_value: 900
  agc_gain_ceiling: 2x

This might not be necessary if you don't need maximum camera resolutions. Or even in some cases - you need them both set to auto.

Disable hardware acceleration (if you see half screen green).

Example: https://www.reddit.com/r/frigate_nvr/comments/176kzon/half_of_the_image_overlayed_in_green/

Disabling hardware acceleration (in Frigate) fixed this for me.

Re-stream to HomeAssistant (Frigate card):

Here is what worked for me the best - latency almost like direct connection to camera:

type: custom:frigate-card
cameras:
  - camera_entity: camera.cam01
    live_provider: go2rtc
    id: cam01
    title: cam01
    go2rtc:
      modes:
        - mjpeg
      stream: cam01

@hjf
Copy link

hjf commented Jan 31, 2024

@erkexzcx I'm using this version: https://github.com/rzeldent/esp32cam-rtsp, Have you used this?
It seems none of the streams it produces (RTSP and MJPEG) are compatible with ffmpeg. The RTSP stream works fine for viewing and snapshot on frigate, but I've tried all combinations of options for go2rtc and it simply won't work.

I get WRN [rtsp] error="codecs not match: JPEG" stream=pasillo for the MJPEG stream or WRN [rtsp] error="source 0 error: exec: exit status 1" stream=pasillo for the RTSP stream.

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

No branches or pull requests

5 participants