feat: squelette stopmotion.sh (options, validation, garde-fous)
This commit is contained in:
1 file changed
+55
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage : $(basename "$0") [options]
|
||||
|
||||
Crée une vidéo stop motion à partir d'un dossier d'images.
|
||||
|
||||
Options :
|
||||
-i DIR dossier d'images (défaut : ./images)
|
||||
-o FILE fichier de sortie (défaut : ./stop_motion.mp4)
|
||||
-f FPS cadence en images/seconde, > 0 (défaut : 12)
|
||||
-s SIZE taille max du côté long en pixels, > 0 (défaut : 1080)
|
||||
-y écraser le fichier de sortie sans demander
|
||||
-h afficher cette aide
|
||||
EOF
|
||||
}
|
||||
|
||||
INPUT="images"
|
||||
OUTPUT="stop_motion.mp4"
|
||||
FPS="12"
|
||||
SIZE="1080"
|
||||
ASSUME_YES=0
|
||||
|
||||
while getopts ":i:o:f:s:yh" opt; do
|
||||
case $opt in
|
||||
i) INPUT=$OPTARG ;;
|
||||
o) OUTPUT=$OPTARG ;;
|
||||
f) FPS=$OPTARG ;;
|
||||
s) SIZE=$OPTARG ;;
|
||||
y) ASSUME_YES=1 ;;
|
||||
h) usage ; exit 0 ;;
|
||||
\?) echo "Erreur : option inconnue -$OPTARG" >&2 ; usage >&2 ; exit 1 ;;
|
||||
:) echo "Erreur : valeur manquante pour -$OPTARG" >&2 ; usage >&2 ; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ! [[ $FPS =~ ^[0-9]+([.][0-9]+)?$ ]] || ! awk -v f="$FPS" 'BEGIN{exit !(f>0)}'; then
|
||||
echo "Erreur : -f doit être un nombre strictement positif (reçu : $FPS)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [[ $SIZE =~ ^[0-9]+$ ]] || ! awk -v s="$SIZE" 'BEGIN{exit !(s>0)}'; then
|
||||
echo "Erreur : -s doit être un entier strictement positif (reçu : $SIZE)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v ffmpeg >/dev/null 2>&1; then
|
||||
echo "Erreur : ffmpeg est introuvable. Installation : brew install ffmpeg" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$INPUT" ]; then
|
||||
echo "Erreur : le dossier d'images '$INPUT' n'existe pas." >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user