Way to get HTTP/HTTPS camera stream with Authorization HTTP-header
I've been hitting my head to wall how to solve the issue. I've been iterating the configuration so many way that I cannot write them down anymore.
running on docker: (latest downloaded 2022-09-29) alexxit/go2rtc latest fe926956f681 7 days ago 249MB
config which is the closest:
streams:
kc120: 'ffmpeg:https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71#video=h264#raw=-headers "Authorization: Basic --base64-encoded-credentials-of-mine--\r\n\"'
- I needed to use #raw= to get header even visible on exec command line.
- on web page passing http headers to ffmpeg is: ffmpeg -headers $'X-API-KEY: MyApiKey\r\nX-API-SECRET:asfd\r\n' -i http://localhost:8080/file -v trace
- note the headers vs -i positioning go2rtc compiles, I think ffmpeg requires -i parameter to be the first on ffmpeg-yaml-line
- however by slightly modifying DBG output and running via CLI I get authorization required.
output via trace log:
# docker compose up
[+] Running 1/0
⠿ Container go2rtc-go2rtc-1 Created 0.0s
Attaching to go2rtc-go2rtc-1
go2rtc-go2rtc-1 | s6-rc: info: service s6rc-oneshot-runner: starting
go2rtc-go2rtc-1 | s6-rc: info: service s6rc-oneshot-runner successfully started
go2rtc-go2rtc-1 | s6-rc: info: service fix-attrs: starting
go2rtc-go2rtc-1 | s6-rc: info: service fix-attrs successfully started
go2rtc-go2rtc-1 | s6-rc: info: service legacy-cont-init: starting
go2rtc-go2rtc-1 | s6-rc: info: service legacy-cont-init successfully started
go2rtc-go2rtc-1 | s6-rc: info: service legacy-services: starting
go2rtc-go2rtc-1 | s6-rc: info: service legacy-services successfully started
go2rtc-go2rtc-1 | 17:12:50.579 INF [api] listen addr=:1984
go2rtc-go2rtc-1 | 17:12:50.580 INF [rtsp] listen addr=:8554
go2rtc-go2rtc-1 | 17:12:50.580 INF [srtp] listen addr=:8443
go2rtc-go2rtc-1 | 17:12:55.698 DBG [exec] run url="exec:ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71 -headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\" -codec:v libx264 -g 30 -preset superfast -tune zerolatency -profile main -level 4.1 -pix_fmt yuv420p -an -rtsp_transport tcp -f rtsp rtsp://localhost:8554/7729953a5e4546339830a639b49715d9"
go2rtc-go2rtc-1 | 17:13:10.700 ERR [exec] timeout url="exec:ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71 -headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\" -codec:v libx264 -g 30 -preset superfast -tune zerolatency -profile main -level 4.1 -pix_fmt yuv420p -an -rtsp_transport tcp -f rtsp rtsp://localhost:8554/7729953a5e4546339830a639b49715d9"
go2rtc-go2rtc-1 | 17:13:10.700 ERR [streams] probe producer error=timeout url="ffmpeg:https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71#video=h264#raw=-headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\""
go2rtc-go2rtc-1 | 17:13:10.700 DBG [exec] run url="exec:ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71 -headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\" -codec:v libx264 -g 30 -preset superfast -tune zerolatency -profile main -level 4.1 -pix_fmt yuv420p -an -rtsp_transport tcp -f rtsp rtsp://localhost:8554/7729953a5e4546339830a639b49715d9"
go2rtc-go2rtc-1 | 17:13:25.702 ERR [exec] timeout url="exec:ffmpeg -hide_banner -fflags nobuffer -flags low_delay -i https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71 -headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\" -codec:v libx264 -g 30 -preset superfast -tune zerolatency -profile main -level 4.1 -pix_fmt yuv420p -an -rtsp_transport tcp -f rtsp rtsp://localhost:8554/7729953a5e4546339830a639b49715d9"
go2rtc-go2rtc-1 | 17:13:25.702 ERR [streams] probe producer error=timeout url="ffmpeg:https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G71#video=h264#raw=-headers \"Authorization: Basic --base64-encoded-credentials-of-mine--\\r\\n\\\""
go2rtc-go2rtc-1 | 17:13:25.702 WRN [api.webrtc] add consumer error="couldn't find the matching tracks"
So I am not sure if with go2rtc I can ever succeed with current code-base.
I also tried with curl: exec:curl.sh {output} and curl.sh was mapped to container. This curl.sh with piped ffmpeg if writing to a file test.mp4 is able to produce file to filesystem which can be viewed with VLC. In this case line ending is: ffmpeg -y -i - test.mp4
curl -vv -k -u username:password --ignore-content-length "https://192.168.9.179:19443/https/stream/mixed?video=H264&audio=G711" --output - | ffmpeg -y -hide_banner -re -i - -c copy -rtsp_transport tcp -f rtsp $1
# curl output
go2rtc-go2rtc-1 | 17:21:05.627 DBG [exec] run url="exec:/config/scripts/curl.sh rtsp://localhost:8554/16c408ab505bf866a749e7f1dd542500"
go2rtc-go2rtc-1 | 17:21:05.631 ERR [exec] error="fork/exec /config/scripts/curl.sh: exec format error" url="exec:/config/scripts/curl.sh rtsp://localhost:8554/16c408ab505bf866a749e7f1dd542500"
go2rtc-go2rtc-1 | 17:21:05.631 ERR [streams] probe producer error="fork/exec /config/scripts/curl.sh: exec format error" url="exec:/config/scripts/curl.sh {output}"
go2rtc-go2rtc-1 | 17:21:05.631 DBG [exec] run url="exec:/config/scripts/curl.sh rtsp://localhost:8554/16c408ab505bf866a749e7f1dd542500"
go2rtc-go2rtc-1 | 17:21:05.632 ERR [exec] error="fork/exec /config/scripts/curl.sh: exec format error" url="exec:/config/scripts/curl.sh rtsp://localhost:8554/16c408ab505bf866a749e7f1dd542500"
go2rtc-go2rtc-1 | 17:21:05.632 ERR [streams] probe producer error="fork/exec /config/scripts/curl.sh: exec format error" url="exec:/config/scripts/curl.sh {output}"
go2rtc-go2rtc-1 | 17:21:05.632 WRN [api.webrtc] add consumer error="couldn't find the matching tracks"
Big questions are - am I even close to be able to solve my dilemma? Which approach for solving is better?
Thank you for your attention, cheers, joriws
I also mapped curl.sh to containers /usr/bin if format error is config.yaml path-name before executable. But same error.
go2rtc-go2rtc-1 | 17:36:06.563 DBG [exec] run url="exec:curl.sh rtsp://localhost:8554/0ffd83e9e24c1a956e8787d0940d3d08"
go2rtc-go2rtc-1 | 17:36:06.563 ERR [exec] error="fork/exec /usr/bin/curl.sh: exec format error" url="exec:curl.sh rtsp://localhost:8554/0ffd83e9e24c1a956e8787d0940d3d08"
go2rtc-go2rtc-1 | 17:36:06.564 ERR [streams] probe producer error="fork/exec /usr/bin/curl.sh: exec format error" url="exec:curl.sh {output}"
go2rtc-go2rtc-1 | 17:36:06.564 DBG [exec] run url="exec:curl.sh rtsp://localhost:8554/0ffd83e9e24c1a956e8787d0940d3d08"
go2rtc-go2rtc-1 | 17:36:06.565 ERR [exec] error="fork/exec /usr/bin/curl.sh: exec format error" url="exec:curl.sh rtsp://localhost:8554/0ffd83e9e24c1a956e8787d0940d3d08"
go2rtc-go2rtc-1 | 17:36:06.565 ERR [streams] probe producer error="fork/exec /usr/bin/curl.sh: exec format error" url="exec:curl.sh {output}"
go2rtc-go2rtc-1 | 17:36:06.565 WRN [api.webrtc] add consumer error="couldn't find the matching tracks"
I actually succeeded but adding starting #!/bin/bash to shell-file so that fork realises it to be run with bash.. ;)
Also to be exact, where this myshell.sh should be stored in container. Amonth PATH or can I add full path for shell-script?

The exec path has relevance that can I mount directory full of scripts to go2rtc or do I need to do 'em one by one on docker-compose.yml?
ok I mounted directory to /config/scripts and used exec:curl.sh so go2rtc found it somehow?
Have you tried to add user/pass into http link? Maybe ffmepg support it. Your stream has simple HTTP authorization?
https://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basic-authentication-in-url-parameters
Reopen issue if it still relevant
I also needed this for accessing a stream from home assistant which only appears to allow a Bearer token for accessing it. I ended up making a fork just to work for my use case.
@koosc latest master version supports custom headers for http source
streams:
http-mjpeg1: https://mjpeg.sanford.io/count.mjpeg#header=User-Agent:Something
Awesome, I missed that. Thanks!