-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |