Skip to content

Instantly share code, notes, and snippets.

@georg90
Created April 15, 2020 21:38
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 georg90/9f653c090afd54f67d1ad70f03c6e0bb to your computer and use it in GitHub Desktop.
Save georg90/9f653c090afd54f67d1ad70f03c6e0bb to your computer and use it in GitHub Desktop.
Create thumbnails for videos in piwigo remotely if webspace doesn't allow the install of ffmpeg etc.
#!/bin/bash
# find all video files without thumbnail and create thumbnails remotely (I have a nodered API that can receive the video file and return the thumbnail)
# I run this as a cronjob every day
db=""
host=""
user=""
pw=""
remote_ffmpeg=""
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="/piwigo${path}/pwg_representative/${s%.*}.png"
pathToVideo="/piwigo${value#.}"
echo "will load new thumb ${pathToVideo} and store as ${fullpath}"
/usr/bin/curl -o $fullpath --user "user:pass" -X POST -F "filedata=@${pathToVideo}" $remote_ffmpeg
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"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment