From 32d8a12195a6cec6759abc53a77169a1e4afa321 Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Sun, 18 Dec 2022 12:14:31 -0600 Subject: [PATCH] Made some more progress Commiting to update the current Docker image on ghcr --- .dockerignore | 1 + Dockerfile | 4 ++-- docker-compose.yml | 22 ++++++++++++++++------ main.py | 41 ++++++++++++++++++++++------------------- 4 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e01443b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.config/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f727d92..80ea49f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,5 +38,5 @@ COPY . ./ RUN pip3 install -r requirements.txt # Install wait-for-it so this can easily be used with docker-compose # Example: command: ["./wait-for-it.sh", "bridge:8554", "--", "python", "main.py"] -RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && chmod +x wait-for-it.sh && mv wait-for-it.sh /usr/local/bin -CMD ["python", "main.py"] \ No newline at end of file +RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && chmod +x wait-for-it.sh && mv wait-for-it.sh /bin +CMD ["python3", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml index e8f7783..8182135 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,7 @@ services: all: aliases: - bridge + - wyze-bridge ntfy: image: binwiederhier/ntfy container_name: ntfy-wyze @@ -46,9 +47,18 @@ services: - RUN_BY_COMPOSE=true depends_on: - bridge - # Use wait-for-it to wait for the bridge at port 8888 (hls) to be ready and then run /app/main.py - # command: /bin/bash -c "wait-for-it.sh -h bridge -p 8888 --timeout=0 --strict -- echo "done" && python /app/main.py" - - -# How can this be run and a .env file passed? -# docker-compose up -d --env-file .env + # Use curl to check if the rtsp stream is up, then run the face recognition + command: > + /bin/sh -c " + while true; do + curl -s http://bridge:8888/cv/0.m3u8 > /dev/null + if [ $? -eq 0 ]; then + echo 'Stream is up, running face recognition' + python3 /app/main.py + else + echo 'Stream is down, waiting 5 seconds' + sleep 5 + fi + done + " + \ No newline at end of file diff --git a/main.py b/main.py index 27b2656..3aa90a7 100644 --- a/main.py +++ b/main.py @@ -33,6 +33,8 @@ def write_config(): json.dump(config, config_file, indent=4) +print("Hello, world!") + # Initialize some variables face_locations = [] face_encodings = [] @@ -44,7 +46,7 @@ process_this_frame = True # Load the config file, if it does not exist or is blank, create it config = { # If RUN_BY_COMPOSE is true, set url to rtsp://wyze-bridge:8554/wyze_cam_name, otherwise set it to "rtsp://localhost:8554/wyze_cam_name" - "URL": "rtsp://localhost:8554/wyze_cam_name" if not RUN_BY_COMPOSE else "rtsp://wyze-bridge:8554/wyze_cam_name", + "URL": "rtsp://localhost:8554/wyze_cam_name" if not RUN_BY_COMPOSE else "rtsp://bridge:8554/wyze_cam_name", "run_scale": "0.25", "view_scale": "0.75", "faces": { @@ -85,24 +87,25 @@ else: print(f"Current config: {config}") # Try this 5 times, 5 seconds apart. If the stream is not available, exit -for i in range(5): - # Check if HLS stream is available using the requests library - # If it is not, print an error and exit - try: - # Replace rtsp with http and the port with 8888 - url = URL.replace("rtsp", "http").replace(":8554", ":8888") - r = requests.get(url) - if r.status_code != 200: - print("HLS stream not available, please check your URL") - exit() - except requests.exceptions.RequestException as e: - print("HLS stream not available, please check your URL") - if i == 4: - exit() - else: - print(f"Retrying in 5 seconds ({i+1}/5)") - time.sleep(5) - continue +# for i in range(5): +# # Check if HLS stream is available using the requests library +# # If it is not, print an error and exit +# url = URL.replace("rtsp", "http").replace(":8554", ":8888") +# print(f"Checking if HLS stream is available at {url}...") +# try: +# # Replace rtsp with http and the port with 8888 +# r = requests.get(url) +# if r.status_code != 200: +# print("HLS stream not available, please check your URL") +# exit() +# except requests.exceptions.RequestException as e: +# print("HLS stream not available, please check your URL") +# if i == 4: +# exit() +# else: +# print(f"Retrying in 5 seconds ({i+1}/5)") +# time.sleep(5) +# continue