Skip to content

Instantly share code, notes, and snippets.

@noelhibbard
Last active October 12, 2023 16:49
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noelhibbard/03703f551298c6460f2fd0bfdbc328bd to your computer and use it in GitHub Desktop.
Save noelhibbard/03703f551298c6460f2fd0bfdbc328bd to your computer and use it in GitHub Desktop.
This gist shows how to pull the local stream from a Wyze camera and then push it to an RTMP server.

Installing wyzecam-to-rtmp as systemd service

Install Python 3.8

sudo apt-get install python3.8 python3.8-pip python3.8-venv -y

Create venv

python3.8 -m venv /opt/wyzecam-to-rtmp
cd ~/wyzecam-to-rtmp
source bin/activate

Install dependencies

pip install wyzecam
pip install requests

Download wyzecam-to-rtmp.py and wyzecam-to-rtmp@.service

wget https://gist.github.com/noelhibbard/03703f551298c6460f2fd0bfdbc328bd/raw/08666ddae0fa18e9b3d29ded9e028906400b10a2/wyzecam-to-rtmp.py
wget https://gist.github.com/noelhibbard/03703f551298c6460f2fd0bfdbc328bd/raw/08666ddae0fa18e9b3d29ded9e028906400b10a2/wyzecam-to-rtmp@.service

Create config file, name it what you want but needs to be in /etc/wyzecam-to-rtmp and must have an .env extention.

mkdir /etc/wyzecam-to-rtmp
nano /etc/wyzecam-to-rtmp/Doorbell.env

Paste these contents:

WYZE_EMAIL="joeblow@example.com"
WYZE_PASSWORD="wyzepasshere"
WYZE_CAMERA_NAME="Doorbell"
RTMP_URL="rtmp://127.0.0.1/live/doorbell"

Install systemd service file which you downloaded above

systemctl enable /opt/wyzecam-to-rtmp/wyzecam-to-rtmp@.service

Start the service using what ever config file you created above.

systemctl start wyzecam-to-rtmp@Doorbell
# Edit and rename this file and then place it in /etc/wyzecam-to-rtmp
WYZE_EMAIL="joeblow@example.com"
WYZE_PASSWORD="wyzepasshere"
WYZE_CAMERA_NAME="Doorbell"
RTMP_URL="rtmp://127.0.0.1/live/doorbell"
from wyzecam import get_camera_list, get_user_info, login
from wyzecam.iotc import WyzeIOTC
import sys, signal, subprocess, os
from time import sleep
def main():
def handler(signum, frame):
sys.exit()
signal.signal(signal.SIGINT, handler)
user = os.environ["WYZE_EMAIL"]
password = os.environ["WYZE_PASSWORD"]
cameraname = os.environ["WYZE_CAMERA_NAME"]
rtmpurl = os.environ["RTMP_URL"]
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()
[Unit]
Description=wyzecam-to-rtmp (%I)
After=network.target
Wants=network-online.target
[Service]
Restart=always
KillMode=process
Type=idle
EnvironmentFile=-/etc/wyzecam-to-rtmp/%I.env
ExecStart=/opt/wyzecam-to-rtmp/bin/python /opt/wyzecam-to-rtmp/wyzecam-to-rtmp.py
SyslogIdentifier=wyzecam-to-rtmp-%I
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment