Created
September 21, 2023 12:03
-
-
Save Dimtree/f7313ddadad8bd73ada7e29536bd64d7 to your computer and use it in GitHub Desktop.
Repeatedly take photos from webcam using ffmpeg and upload them to PrusaConnect
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
#!/bin/bash | |
# based on this script by nunofgs | |
# https://gist.github.com/nunofgs/84861ee453254823be6b069ebbce9ad2 | |
# fingerprint needs to be unique per camera | |
# it's just a random string, generate one with `uuidgen` or `pwgen 32 1` | |
# if you lose it, delete and re-add the camera in PrusaConnect then rotate $FINGERPRINT and $TOKEN here | |
FINGERPRINT=fingerprint-goes-here | |
# PrusaConnect "other camera" token | |
TOKEN=token-goes-here | |
DELAY_SEC=10 | |
FAIL_DELAY_SEC=60 | |
ENDPOINT=https://webcam.connect.prusa3d.com/c/snapshot | |
while true; do | |
# Take a screenshot from first attached webcam | |
if ffmpeg \ | |
-y \ | |
-f v4l2 \ | |
-video_size 1280x720 \ | |
-i /dev/video0 \ | |
-r 0.2 \ | |
-qscale:v 2 \ | |
-update 1 \ | |
/tmp/output.jpg | |
then | |
curl \ | |
-X PUT "$ENDPOINT" \ | |
-H "accept: */*" \ | |
-H "content-type: image/jpg" \ | |
-H "fingerprint: $FINGERPRINT" \ | |
-H "token: $TOKEN" \ | |
--data-binary "@/tmp/output.jpg" \ | |
--compressed \ | |
--silent | |
sleep "$DELAY_SEC" | |
else | |
echo "Unable to take photo from webcam. Sleeping ${FAIL_DELAY_SEC}s..." | |
sleep "${FAIL_DELAY_SEC}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment