#!/bin/bash # Generates thumbs if [[ "$1" != "" ]]; then if [[ -L "$1" ]]; then exit fi src="$1" base=$(basename -- "$src") dst=".thumbs/$base" if [[ "$src" -nt "$dst" ]]; then echo "update $dst" if [[ "$src" == *.mp4 ]] || [[ "$src" == *.gif ]]; then dst_tmp="/tmp/$base.png" rm -f "$dst_tmp" ffmpeg -hide_banner -loglevel error -i "$src" -ss 00:00:00.000 -vframes 1 "$dst_tmp" src="$dst_tmp" dst_tmp="/tmp/$base" mv "$src" "$dst_tmp" src="$dst_tmp" fi mogrify -path .thumbs/ -auto-orient -thumbnail 128x128 -quality 90% "$src" rm -f "$dst_tmp" fi else mkdir -p .thumbs find -type f -not -path "./.thumbs/*" \ | grep -iE "\.png$|\.jpg$|\.jpeg$|\.jfif$|\.gif$|\.webp$|\.mp4$" \ | parallel -j$(nproc) "$0" {} fi