Closed joshgetter closed 3 years ago
Hi Josh, I recently came across this page (https://medium.com/@hu3vjeen/reverse-engineering-tp-link-kc100-bac4641bf1cd) - and I managed to replicate from a CentOS7 terminal , the cURL - and it works perfectly with KC100 and KC120 cameras. I tried to redo the cURL under a Python script - so that we can have a definition where the single variable will be the camera IP and from there have multiple feeds from all the cameras. But I am a bit stuck on the conversion and output of the cURL to Python. Maybe we can test this when you have the time. Here is the cURL that I tested and it works:
curl -vv -k -u username:base64_encrypted_password = --ignore-content-length "https://192.168.x.x:19443/https/stream/mixed?video=h264&audio=g711&resolution=hd&deviceId=CAFEDEADBEAFCAFEDEADBEAFCAFEDEADBEAFCAFE" --output - | ffmpeg -y -i - test.mp4
The file is created and can be viewed without issues. I do not know yet how to turn this into a stream.
Here is what I tried regarding a Py def:
def office_camera_stream(camera_ip):
import requests, ffmpeg
address = "https://" + camera_ip + ":19443/https/stream/mixed?video=h264&audio=g711&resolution=hd&deviceId=CAFEDEADBEAFCAFEDEADBEAFCAFEDEADBEAFCAFE"
#print address
headers = {"authorization": "Basic <AUTH STRING>", #here should be the username in clear as per the cURL and ":" and the password encrypted in base64
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-us"
}
query = ""
response = requests.request("GET", address, headers=headers, data=query, verify=False)
#print response.json()
return
office_camera_stream("192.168.x.x")
However, unfortunately I do not know how to output this into a ffmpeg stream .
An updated py script would be the following, using session:
s = Session()
s.verify = False
address = "https://192.168.x.x:19443/https/stream/mixed?video=h264&audio=g711&resolution=hd&deviceId=CAFEDEADBEAFCAFEDEADBEAFCAFEDEADBEAFCAFE"
headers = {"Authorization": "Basic <AUTH STRING>",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-us",
"Content-Length": "30"
}
response = Request("GET", address, headers=headers)
prep = response.prepare()
r = s.send(prep)
and this works, as it creates the stream - but the stream needs to be converted via ffmpeg
Tech-Specs
It might make sense to create a "Camera" class which will have its own "State", "HealthChecker", and "Wrapper" instance. The controller would then have a "Camera" instance per physical camera.
Another option - it may be possible to have a single Ffmpeg instance with multiple streams. This would probably save some resources but may be tricky to monitor the health since one ffmpeg instance would have multiple output streams. See StackOverflow.