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

Kasa KC200 no video using config.yaml and No Audio with workaround script. #1006

Closed
mechanysm opened this issue Mar 18, 2024 · 12 comments
Closed
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@mechanysm
Copy link

Been trying to get this going for a couple of days, I can see the video stream in Fiddler but can't seem to get it working in go2rtc, i'm running a container with 1.8.5 so looks to be supported.

Getting this error:
undefined error=streams: Get "https://[email protected]:***@192.168.1.19:19443/https/stream/mixed?video=H264&audio=G711": net/http: HTTP/1.x transport connection broken: bad Content-Length "-1" caller=github.com/AlexxIT/go2rtc/internal/mjpeg/init.go:166

my config is basic and as follows

streams:
  kasa: kasa://[email protected]:[email protected]:19443/https/stream/mixed?video=H264&audio=G711

reponse header contains the following

Content-Type: multipart/x-mixed-replace;boundary=data-boundary--

This seems to correspond to the body which contains --data-boundary-- prior to the av content.

Any help would be much appreciated as feel like I'm so close

@mechanysm
Copy link
Author

Thought I would add some extra information, hopefully its helpful, this is scrapped from fiddler.

Request Header

GET https://192.168.1.19:19443/https/stream/mixed?video=H264&audio=G711 HTTP/1.1
Authorization: Basic <Base64 Token>
Connection: keep-alive
User-Agent: Dalvik/2.1.0 (Linux; U; Android 14; SM-S901E Build/UP1A.231005.007)
Host: 192.168.1.19:19443
Accept-Encoding: gzip

Response Header + data boundary

HTTP/1.0 200 OK
Server: Streamd,
Date: Tue, 19 Mar 2024 18:19:18 UTC
Content-Type: multipart/x-mixed-replace;boundary=data-boundary--
Pragma: no-cache
Cache-Control: no-cache
Connection: keep-alive
Content-Encoding: gzip

�‹�     �  A@¾¿--data-boundary--
Content-Type: video/x-h264
Content-Length: 140257
X-UtcTime:1710872358
X-Timestamp: 7420219.405023
X-Audio: 1
X-FrameType: 0
X-FrameRate: 12.5
X-Video-Detection: 0

   �gM *�¸� ‰ùfà   @   �hî<€   ��å�K€   �e¸  B�OìR�1‚&Ÿ&ê�0áM×�� }�.�9®Äm¾ñÞ¬¡ÎÒáÇ囋o?¹��uU"�$NÑ�‚¬ÿõ��'¾÷�}—ûRdý�ZžË�%=À�=„²rù5Ú�À'ö/Õ�â�üÈU��|ÛÿFß

@mechanysm
Copy link
Author

mechanysm commented Mar 20, 2024

Was able to successfully get a video output with curl, still no luck with go2rtc :(

curl -k -u '[email protected]:<password>' --ignore-content-length "https://192.168.1.19:19443/https/stream/mixed?video=H264&audio=G711" --output - | ffmpeg -hide_banner -y -i - -vcodec copy ./ffmpeg/test.mp4

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  929k    0  929k    0     0  81562      0 --:--:--  0:00:11 --:--:-- 88529Input #0, h264, from 'pipe:':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Output #0, mp4, to './ffmpeg/test.mp4':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 25 fps, 25 tbr, 1200k tbn, 1200k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
[mp4 @ 0x55891c575480] 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
100 1012k    0 1012k    0     0  81737      0 --:--:--  0:00:12 --:--:-- 89509frame=  142 fps=135 q=-1.0 size=     768kB tim100 1086k    0 1086k    0     0  81395      0 --:--:--  0:00:13 --:--:-- 88729frame=  156 fps= 72 q=-1.0 size=    1024kB tim100 1167k    0 1167k    0     0  81362      0 --:--:--  0:00:14 --:--:-- 89980frame=  170 fps= 51 q=-1.0 size=    1024kB tim

Hopefully this is helpful in some way :)

@mechanysm
Copy link
Author

Have created a ngrok tunnel for the camera if that helps.

@mechanysm
Copy link
Author

Well I bodged my way around some of my issues, I now have some video, not perfect so would still be keen to have this issue resolved if that's possible?

It feels like the current go2rtc implementation is very close but I get the feeling the issue is with the --data-boundary-- and the weird issues with audio being mixed into the same stream as its very intermittent, I assume its only sending audio through when there is something over a certain db level.

I tried to create some rather elaborate bash scripts to split out the audio and video into separate FIFO's but I think along with the overhead its just to slow and ffmpeg didn't seem to like it when I was trying to recombine it and the FIFO's were flaky at best.

I have settled on the following script which loads the video relatively quickly compared to previous attempts, I have the codec for audio in it but it doesn't work :(

#!/bin/bash

# make fifo if needed.
[ -p stream.fifo ] || mkfifo stream.fifo

# Pipe video and audio to fifo.
curl -s -k -u '[email protected]:<encoded password>' --ignore-content-length "https://192.168.1.19:19443/https/stream/mixed?video=H264&audio=G711" --output stream.fifo &

# ffmpeg convert to something les broken.
ffmpeg -hide_banner -i stream.fifo -c:v copy -c:a pcm_mulaw -f flv - &

# wait for ffmpeg to end before closing.
wait

#done
exit

Using the docker version of go2rtc so created a script folder in config and mapped the path across, dumped the script in there and ran chmod +x ./scriptname.sh on it to give it execute.

Audio data boundary below, there are some odd things going on, its almost like it finishes the audio then starts the video again without a new --data-boundary-- though this may be my noob knowledge of audio\video streams.

--data-boundary--
Content-Length: 480
X-Timestamp: 7420238.689837
Content-Type: audio/g711u

Some additional information I found in my travels

  • Port 18443 - Appears to be the speaker
  • TPLink seem to have the "GPL firmware" published on their site, its just openwrt, is this camera based on this?
  • Looks to be a serial header on the PCB, I may have a go at this in the future :P
  • ffmpeg seems to indicate there is a second yuvj420p stream but haven't played with it as video works well enough.

@mechanysm mechanysm changed the title Kasa KC200 bad Content-Length "-1" Kasa KC200 bad Content-Length "-1" and No Audio with workaround script. Mar 24, 2024
@mechanysm mechanysm changed the title Kasa KC200 bad Content-Length "-1" and No Audio with workaround script. Kasa KC200 no video using config.yaml and No Audio with workaround script. Mar 24, 2024
@charlieamer
Copy link

I believe go2rtc doesn't perfectly handle streams for kasa. There is homeassistant addon which I believe handles it much better, but it has its own flaws. https://github.com/joshgetter/hassio-addons/tree/master/kasa-camera . This one is splitting and recombining streams properly though. I am considering to sell the KC200 camera and buy a different one with better support, one that's less propriatory 😅

@mechanysm
Copy link
Author

Thanks @charlieamer its funny you say that as I have just ordered two new (less known brand) onvif based cameras, hopefully I dont regret this purchase, guess I will find out soon, I don't have a lot of money though so my options were slim.

@charlieamer
Copy link

Thanks @charlieamer its funny you say that as I have just ordered two new (less known brand) onvif based cameras, hopefully I dont regret this purchase, guess I will find out soon, I don't have a lot of money though so my options were slim.

I found a way to connect go2rtc/frigate with kasa! It requires a custom python script. I'll send details soon. I am certain the solution could be integrated in golang as well, as part of native go2rtc ecosystem.

@AlexxIT AlexxIT added the bug Something isn't working label Apr 20, 2024
@AlexxIT AlexxIT self-assigned this Apr 20, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Apr 20, 2024

You can send the accesses to your camera to me in PM.

@saintyuk
Copy link

saintyuk commented May 8, 2024

Any updates? I can potentially help if useful :)

@AlexxIT
Copy link
Owner

AlexxIT commented May 8, 2024

I'm waiting PMs

@saintyuk
Copy link

saintyuk commented May 9, 2024

I've added you as a friend on Discord. I have a spare KC200 we can play about with 👍

Edit: KC420WS works perfectly with go2rtc including audio!

@AlexxIT AlexxIT added duplicate This issue or pull request already exists and removed bug Something isn't working labels May 10, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented May 10, 2024

This is duplicate #725
Fixed in latest master version

@AlexxIT AlexxIT closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants