AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
5.04k stars 401 forks source link

Issues using exec, curl, and pipes #551

Closed Sammy1Am closed 1 year ago

Sammy1Am commented 1 year ago

I'm running into an issue with a bit of a niche use case. I have a KC401 camera that exposes a sort of weird MJPEG stream that I can only seem to consume via ffmpeg. This command successfully creates a working .mp4 file:

curl -vv -k -u "me@example.com:pAsShAsH" --ignore-content-length https://192.168.0.127:19443/https/stream/mixed --output - | ffmpeg -i - test.mp4

I think the root problem ends up being a combination of curl's parsing and go2rtc's QuoteSplit function.

I initially (naively) tried:

streams:
  test1: exec:curl -vv -k -u "me@example.com:pAsShAsH" --ignore-content-length https://192.168.0.127:19443/https/stream/mixed --output - | ffmpeg -i - test.mp4

But go.exec doesn't do pipes, so I have to wrap things in a bash -c command. This is where the quote issues come to play. There's two ways I can think of to do this:

streams:
  test2: exec:bash -c 'curl -vv -k -u "me@example.com:pAsShAsH" --ignore-content-length https://192.168.0.127:19443/https/stream/mixed --output - | ffmpeg -i - test.mp4'
  test3: exec:bash -c "curl -vv -k -u 'me@example.com:pAsShAsH' --ignore-content-length https://192.168.0.127:19443/https/stream/mixed --output - | ffmpeg -i - test.mp4"

But test2 fails, I think, because QuoteSplit is only looking for double quotes so the bash argument gets all mangled. And test3 fails because for whatever reason curl just includes the single quotes as part of the username. The quotes around the username:password is required because without them curl's parser gets confused by the username being an email address and I get a "no such file or directory" error.

Am I missing some other way to process this stream? Can QuoteSplit be modified to also look for single quotes and support quotes-in-quotes as escaped quotes? Or some other quote-escaping process so I can pass double-quotes to the curl command?

Additional context: ffmpeg can't directly consume the stream because of the required --ignore-content-length which only curl seems to support. If I just put curl in without the ffmpeg, I get an unknown format error.

Sammy1Am commented 1 year ago

Alright, FWIW, I've worked around the issue by putting the original command that works in a shell script, mounting that script via docker, and then using exec:bash thescript.sh.

Will leave this open just for a bit to see if:

AlexxIT commented 1 year ago

Here you output video to file. But not to go2rtc exec:curl xxx - | ffmpeg -i - test.mp4

Sammy1Am commented 1 year ago

Ah, yeah, sorry, just copy-pasted wrong. It's ... | ffmpeg -i - -f h264 -

AlexxIT commented 1 year ago

Can you share stream with me? https://github.com/AlexxIT/go2rtc/wiki/Tunnel-RTSP-camera-to-Intenet You can find contacts in the github profile.

Sammy1Am commented 1 year ago

Info sent on Discord.

AlexxIT commented 1 year ago

TP-Link Kasa source added to latest version https://github.com/AlexxIT/go2rtc/releases/tag/v1.7.0