Skip to content

Instantly share code, notes, and snippets.

@clement-analogue
Created May 9, 2020 22:34
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 clement-analogue/24b67f8e1381ec2595a8faae82b25ea0 to your computer and use it in GitHub Desktop.
Save clement-analogue/24b67f8e1381ec2595a8faae82b25ea0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# find all video files without thumbnail and create thumbnails
db=""
host="mysql.example.com"
user=""
pw=""
mysql -h $host -P 3306 -D$db -u$user -p$pw -se 'SELECT id,path FROM `piwigo_images` where representative_ext is null and right(file,3) = "mp4"' | while read -r id value;
do
s=${value##*/}
echo "missing for ${value##*/}"
path=$(dirname "${value#.}")
# this is specific to my installation..
fullpath="/var/www/html/photos${path}/pwg_representative/${s%.*}.png"
pathToVideo="/var/www/html/photos${value#.}"
echo "will load new thumb ${pathToVideo} and store as ${fullpath}"
ffmpeg -i $pathToVideo -ss 00:00:04.000 -vframes 1 $fullpath
if [ $? -eq 0 ]; then
echo "OK, thumb created"
dbquery=$(mysql -h $host -P 3306 -D$db -u$user -p$pw -se 'UPDATE `piwigo_images` SET representative_ext = "png" WHERE id = "'${id}'";')
if [ $? -eq 0 ]; then
echo "OK, db sync done"
else
echo "Error"
exit 1
fi
else
echo "Error"
exit 1
fi
done
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment