Skip to content

Instantly share code, notes, and snippets.

@microtherion
Created January 31, 2024 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microtherion/01c2c8005defd79300ac08528555b69c to your computer and use it in GitHub Desktop.
Save microtherion/01c2c8005defd79300ac08528555b69c to your computer and use it in GitHub Desktop.
Linking an RTSP based camera (e.g. webcam) with unusable snapshots to Prusa Connect
#!/bin/sh
#
# prusa_rtsp_upload - Upload stills from an RTSP camera to Prusa Connect
#. Uses ffmpeg to take snapshots of the video feed, for cameras whose
#. snapshot URL produces low quality snapshots
#
# Copyright (C) 2024 Matthias Neeracher <microtherion@gmail.com>
# Licensed under CC-BY terms: https://creativecommons.org/licenses/by/4.0/
#
# Prerequisites: ffmpeg, curl
URL='https://webcam.connect.prusa3d.com/c/snapshot'
CAMERA='rtsp://admin:@192.168.1.58:554/0/video0' # REPLACE with your own video URL
TOKEN='BCNzDVLwIRwpnOD64QOn' # REPLACE with token issued by Prusa Connect
# Picking a random but reasonably static value
FINGERPRINT=`ifconfig | grep ether | sort | head -1 | md5`
INTERVAL=10
ffmpeg -i $CAMERA -vf fps=1/$INTERVAL img%08d.jpg -loglevel verbose 2>&1 | grep --line-buffered Statistics | while read x; do
image=`ls *.jpg|head -1`
curl $URL -H 'Content-Type: image/jpg' -H "fingerprint: $FINGERPRINT" -H "token: $TOKEN" -T $image
printf "\015"$image
rm $image
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment