Made some more progress

Commiting to update the current Docker image on ghcr
This commit is contained in:
slashtechno 2022-12-18 12:14:31 -06:00
parent 4acbba41f9
commit 32d8a12195
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
4 changed files with 41 additions and 27 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
.config/

View File

@ -38,5 +38,5 @@ COPY . ./
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
# Install wait-for-it so this can easily be used with docker-compose # Install wait-for-it so this can easily be used with docker-compose
# Example: command: ["./wait-for-it.sh", "bridge:8554", "--", "python", "main.py"] # 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 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 ["python", "main.py"] CMD ["python3", "main.py"]

View File

@ -18,6 +18,7 @@ services:
all: all:
aliases: aliases:
- bridge - bridge
- wyze-bridge
ntfy: ntfy:
image: binwiederhier/ntfy image: binwiederhier/ntfy
container_name: ntfy-wyze container_name: ntfy-wyze
@ -46,9 +47,18 @@ services:
- RUN_BY_COMPOSE=true - RUN_BY_COMPOSE=true
depends_on: depends_on:
- bridge - bridge
# Use wait-for-it to wait for the bridge at port 8888 (hls) to be ready and then run /app/main.py # Use curl to check if the rtsp stream is up, then run the face recognition
# command: /bin/bash -c "wait-for-it.sh -h bridge -p 8888 --timeout=0 --strict -- echo "done" && python /app/main.py" command: >
/bin/sh -c "
while true; do
# How can this be run and a .env file passed? curl -s http://bridge:8888/cv/0.m3u8 > /dev/null
# docker-compose up -d --env-file .env 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
"

41
main.py
View File

@ -33,6 +33,8 @@ def write_config():
json.dump(config, config_file, indent=4) json.dump(config, config_file, indent=4)
print("Hello, world!")
# Initialize some variables # Initialize some variables
face_locations = [] face_locations = []
face_encodings = [] face_encodings = []
@ -44,7 +46,7 @@ process_this_frame = True
# Load the config file, if it does not exist or is blank, create it # Load the config file, if it does not exist or is blank, create it
config = { 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" # 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", "run_scale": "0.25",
"view_scale": "0.75", "view_scale": "0.75",
"faces": { "faces": {
@ -85,24 +87,25 @@ else:
print(f"Current config: {config}") print(f"Current config: {config}")
# Try this 5 times, 5 seconds apart. If the stream is not available, exit # Try this 5 times, 5 seconds apart. If the stream is not available, exit
for i in range(5): # for i in range(5):
# Check if HLS stream is available using the requests library # # Check if HLS stream is available using the requests library
# If it is not, print an error and exit # # If it is not, print an error and exit
try: # url = URL.replace("rtsp", "http").replace(":8554", ":8888")
# Replace rtsp with http and the port with 8888 # print(f"Checking if HLS stream is available at {url}...")
url = URL.replace("rtsp", "http").replace(":8554", ":8888") # try:
r = requests.get(url) # # Replace rtsp with http and the port with 8888
if r.status_code != 200: # r = requests.get(url)
print("HLS stream not available, please check your URL") # if r.status_code != 200:
exit() # print("HLS stream not available, please check your URL")
except requests.exceptions.RequestException as e: # exit()
print("HLS stream not available, please check your URL") # except requests.exceptions.RequestException as e:
if i == 4: # print("HLS stream not available, please check your URL")
exit() # if i == 4:
else: # exit()
print(f"Retrying in 5 seconds ({i+1}/5)") # else:
time.sleep(5) # print(f"Retrying in 5 seconds ({i+1}/5)")
continue # time.sleep(5)
# continue