Files
Bratonien-Adventskalender/adventskalender/2025/tools/convert.sh

146 lines
3.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IMG_INPUT="$SCRIPT_DIR/../assets/images/originals"
VID_INPUT="$SCRIPT_DIR/../assets/videos/originals"
BASE_OUTPUT="$SCRIPT_DIR/../assets"
IMAGE_SIZES=(480 720 1024 1366 1600 1920 2560 3840)
IMAGE_FORMATS=("avif" "webp" "jpeg")
echo "$SCRIPT_DIR"
echo "$BASE_OUTPUT"
# Videonamen (Ordner)
VIDEO_NAMES=(
"nHD"
"FWVGA"
"qHD"
"HD"
"HDplus"
"FullHD"
"1440p"
"4K"
)
# Videogrößen (ffmpeg scale)
VIDEO_SCALES=(
"640:360"
"854:480"
"960:540"
"1280:720"
"1600:900"
"1920:1080"
"2560:1440"
"3840:2160"
)
VIDEO_FORMATS=("mp4" "webm")
###############################################
# BILDER
###############################################
process_images() {
echo "🖼️ Starte Bildverarbeitung..."
for img in "$IMG_INPUT"/*.png; do
[ -e "$img" ] || continue
filename=$(basename "$img")
name="${filename%.*}"
width=$(magick identify -format "%w" "$img")
height=$(magick identify -format "%h" "$img")
orientation="landscape"
[ "$height" -gt "$width" ] && orientation="portrait"
echo "Bild: $filename ($orientation)"
for size in "${IMAGE_SIZES[@]}"; do
for fmt in "${IMAGE_FORMATS[@]}"; do
OUT_DIR="$BASE_OUTPUT/images/$size/$fmt"
mkdir -p "$OUT_DIR"
OUT_FILE="$OUT_DIR/$name.$fmt"
if [ -f "$OUT_FILE" ]; then
echo "⏩ Skip: $name.$fmt existiert bereits ($size)"
continue
fi
if [ "$orientation" = "landscape" ]; then
magick "$img" -resize "${size}" "$OUT_FILE"
else
magick "$img" -resize "x${size}" "$OUT_FILE"
fi
done
done
done
}
###############################################
# VIDEOS
###############################################
process_videos() {
echo "🎬 Starte Videobearbeitung..."
for vid in "$VID_INPUT"/*.mp4; do
[ -e "$vid" ] || continue
filename=$(basename "$vid")
name="${filename%.*}"
echo "Video: $filename"
# über Index 07 iterieren
for i in "${!VIDEO_NAMES[@]}"; do
res="${VIDEO_NAMES[$i]}"
scale="${VIDEO_SCALES[$i]}"
for vfmt in "${VIDEO_FORMATS[@]}"; do
OUT_DIR="$BASE_OUTPUT/videos/$res/$vfmt"
mkdir -p "$OUT_DIR"
OUT_FILE="$OUT_DIR/$name.$vfmt"
if [ -f "$OUT_FILE" ]; then
echo "⏩ Skip: $name.$vfmt existiert bereits ($res)"
continue
fi
if [ "$vfmt" = "mp4" ]; then
ffmpeg -y -i "$vid" -vf "scale=$scale" \
-c:v libx264 -crf 23 -preset medium \
-c:a copy \
"$OUT_FILE"
else
ffmpeg -y -i "$vid" -vf "scale=$scale" \
-c:v libvpx-vp9 -b:v 0 -crf 32 \
-c:a libopus \
"$OUT_FILE"
fi
done
done
done
}
###############################################
echo "----------------------------------------------"
echo " Bratonischer Medien-Konverter gestartet"
echo " Skriptort: $SCRIPT_DIR"
echo "----------------------------------------------"
process_images
process_videos
echo "----------------------------------------------"
echo " Fertig! Nur fehlende Dateien wurden erzeugt."
echo "----------------------------------------------"