It was quite the journey. Convert itself is not the problem, its the automatic duplication ala rsync thats challenging.
Here is my script, which is unique for this purpose, it seems noone has attempted something like that ever before (at least nothing comparable can be found)
Code:
#!/bin/bash
originalsPicturesFolder="/home/xxx/Pictures/"
#transfer newly added images in the library to the photoview server
#there is one local export-direcory as reference. All photos and videos are resized amd transcoded into the export-directory
#from there the images are transferred to the server where the are automatically imported
#first detox all filenames (remove special characters and spaces), because that could mess up the following operations
/usr/bin/detox -r $originalsPicturesFolder
#convert all png/tif images and remove the originals
find $originalsPicturesFolder -iname "*.png" -exec /usr/bin/mogrify -format jpg -quality 85 "{}" \;
find $originalsPicturesFolder -iname "*.tif" -exec /usr/bin/mogrify -format jpg -quality 85 "{}" \;
find $originalsPicturesFolder -iname "*.png" -exec rm "{}" \;
find $originalsPicturesFolder -iname "*.tif" -exec rm "{}" \;
#convert all MOV files (MOV extension will be still present after that, MOV.mp4, but its an insecure hassle to change that in find-exec
find $originalsPicturesFolder -iname '*.mov' -exec ffmpeg -i {} -vcodec h264 -acodec mp2 -hide_banner -loglevel error -f mp4 {}.mp4 \; -exec touch -r {} {}.mp4 \;
find $originalsPicturesFolder -iname "*.mov" -exec rm "{}" \;
#then delete all files that are not present in the master anymore, without updating anything
/usr/bin/rsync -r --delete --existing --ignore-existing $originalsPicturesFolder /mnt/picExport
#parse array from rsync
i=0
while read line
do
filearray[ $i ]="$line"
(( i++ ))
newFile="/mnt/picExport/"$line
masterFile="$originalsPicturesFolder$line"
newDIR="$(dirname "${newFile}")"
filename=$(basename -- "$masterFile")
extension="${filename##*.}"
filename="${filename%.*}"
#rsync is returning the directory itself, so just check against the file extensions (as long as a directory is not called jpg it works, but convert will just throw an error when directory is given)
if [[ "$extension" = "jpg" ]]; then
#create directory if not existent
mkdir -p $newDIR
#reduce image quality because its mainly used on mobile and web, originals are still here so we can just crank up quality in the feature and reconvert everything
convert $masterFile -resize "3000x3000>" -quality 60 $newFile
continue
fi
if [[ "$extension" = "mp4" ]]; then
#create directory if not existent
mkdir -p $newDIR
#just copy the video as there is not much to gain in transcoding
cp $masterFile $newFile
continue
fi
echo "Unkown file: "$newFile" with the extension: "$extension
#rsync is used to determine what files are new, in this special mode only the filename is compared and a list is generated
#save the output of rsync in an array
done < <(/usr/bin/rsync -rn --ignore-existing --out-format="%n" $originalsPicturesFolder /mnt/picExport)
#now push everything to the library server
/usb/bin/rsync -ae --delete "ssh -i /home/xxx/.ssh/id_rsa" /mnt/picExport/ root@server:/media/pics
Bookmarks