Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jtee3d authored Dec 20, 2023
1 parent 125d52d commit 498ef91
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use Alpine as the base image
FROM alpine:3.19.0

# Copy upload.sh
COPY upload.sh upload.sh

# Install bash, curl, and ffmpeg
RUN apk add --no-cache bash curl ffmpeg

# Set the entrypoint
ENTRYPOINT ["/bin/bash", "/upload.sh"]
65 changes: 65 additions & 0 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

trap "echo SIGINT received, exiting...; exit 0" INT


echo " ██╗████████╗███████╗███████╗██████╗ ██████╗"
echo " ██║╚══██╔══╝██╔════╝██╔════╝╚════██╗██╔══██╗"
echo " ██║ ██║ █████╗ █████╗ █████╔╝██║ ██║"
echo "██ ██║ ██║ ██╔══╝ ██╔══╝ ╚═══██╗██║ ██║"
echo "╚█████╔╝ ██║ ███████╗███████╗██████╔╝██████╔╝"
echo " ╚════╝ ╚═╝ ╚══════╝╚══════╝╚═════╝ ╚═════╝ "
echo ""
echo "This script sends snapshots of RTSP streams to Prusa Connect."
echo ""
: "${PRUSA_URL:=https://webcam.connect.prusa3d.com/c/snapshot}"
: "${RTSP_URLS:=}"
: "${TOKENS:=}"

RTSP_URLS=$(echo "$RTSP_URLS" | tr -d ' ')
TOKENS=$(echo "$TOKENS" | tr -d ' ')

IFS="," read -ra RTSP_URLS <<< "$RTSP_URLS"
IFS="," read -ra TOKENS <<< "$TOKENS"

FINGERPRINTS=()
for i in $(seq 1 ${#RTSP_URLS[@]}); do
FINGERPRINTS+=($(printf "camera%010d" $i))
done
echo "Input variables:"
for i in "${!RTSP_URLS[@]}"; do
echo "Camera $((i + 1)), ${RTSP_URLS[$i]}, ${TOKENS[$i]}"
done

while true; do
for i in "${!RTSP_URLS[@]}"; do
echo "Processing camera: $((i + 1))"
echo "RTSP URL: ${RTSP_URLS[$i]}"
echo "Token: ${TOKENS[$i]}"
echo "Fingerprint: ${FINGERPRINTS[$i]}"
echo "------"
ffmpeg \
-loglevel error \
-y \
-rtsp_transport tcp \
-i "${RTSP_URLS[$i]}" \
-f image2 \
-vframes 1 \
-pix_fmt yuvj420p \
output_$i.jpg
if [ $? -eq 0 ]; then
curl -X PUT "$PRUSA_URL" \
-H "accept: */*" \
-H "content-type: image/jpg" \
-H "fingerprint: ${FINGERPRINTS[$i]}" \
-H "token: ${TOKENS[$i]}" \
--data-binary "@output_$i.jpg" \
--no-progress-meter \
--compressed
else
echo "FFmpeg returned an error for camera $((i + 1))."
fi
sleep 1
done
sleep 10
done

0 comments on commit 498ef91

Please sign in to comment.