]> git.lizzy.rs Git - dirlistozxa.git/commitdiff
gen-thumbs: generate video thumbnails master
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Sat, 29 Apr 2023 20:44:47 +0000 (22:44 +0200)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Sat, 29 Apr 2023 20:45:11 +0000 (22:45 +0200)
gen-thumbs

index 13bffe17e5616ec7aa6c07d8d9ee47da63858f9f..934be30f43a040c386f2fdddd8b1368f6d5d9abf 100755 (executable)
@@ -2,13 +2,37 @@
 
 # Generates thumbs
 
-if [ "$1" != "" ]; then
-       target_file=.thumbs/$(basename -- "$1")
-       if [ "$1" -nt "$target_file" ]; then
-               echo "update $target_file"
-               mogrify -path .thumbs/ -auto-orient -thumbnail 128x128 -quality 90% "$1"
+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 -not -path "./.thumbs/*" \( -iname "*.png" -or -iname "*.jpg" -or -iname "*.jpeg" -or -iname "*.jfif" -or -iname "*.gif" -or -iname "*.webp" \) | parallel -j$(nproc) "$0" {}
+       find -type f -not -path "./.thumbs/*" \
+               | grep -iE "\.png$|\.jpg$|\.jpeg$|\.jfif$|\.gif$|\.webp$|\.mp4$" \
+               | parallel -j$(nproc) "$0" {}
 fi