Skip to content

Instantly share code, notes, and snippets.

@noelhibbard
Created June 24, 2021 06:14
Show Gist options
  • Save noelhibbard/02870a26dda8d120f0a5b6f646677280 to your computer and use it in GitHub Desktop.
Save noelhibbard/02870a26dda8d120f0a5b6f646677280 to your computer and use it in GitHub Desktop.
from wyzecam import get_camera_list, get_user_info, login
from wyzecam.iotc import WyzeIOTC
import getopt, sys, signal, subprocess
from time import sleep
def main():
def handler(signum, frame):
sys.exit()
signal.signal(signal.SIGINT, handler)
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["user=", "password=", "cameraname=", "url="])
except getopt.GetoptError as err:
print("--user=<wyzeuser> --password=<wyzepassword> --cameraname=<cameraname> --url=<rtmpServerUrl>")
sys.exit(2)
user = None
password = None
cameraname = None
rtmpurl = None
for opt, arg in opts:
if opt == "--user":
user = arg
if opt == "--password":
password = arg
if opt == "--cameraname":
cameraname = arg
if opt == "--url":
rtmpurl = arg
if user == None or password == None or cameraname == None or rtmpurl == None:
print("--user=<wyzeuser> --password=<wyzepassword> --cameraname=<cameraname> --url=<rtmpServerUrl>")
sys.exit(2)
auth_info = login(user, password)
account = get_user_info(auth_info)
cameras = get_camera_list(auth_info)
cam = [camera for camera in cameras if camera.nickname == cameraname][0]
ffmpeg = subprocess.Popen(['ffmpeg',
'-f', 'h264',
'-i', '-',
'-vcodec', 'copy',
'-f','flv', rtmpurl], stdin=subprocess.PIPE)
while True:
with WyzeIOTC() as wyze_iotc:
try:
with wyze_iotc.connect_and_auth(account, cam) as sess:
session_info = sess.session_check()
for (frame, frame_info) in sess.recv_video_data():
ffmpeg.stdin.write(frame)
except:
print("Reconnect")
sleep(1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment