-
-
Save pbuckley4192/495ae763c6c6c05b9326cbf65a220cfc to your computer and use it in GitHub Desktop.
Parallel recursive RAW to JPEG + meta converter shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/bin/env bash | |
# | |
# Parallel recursive RAW to JPEG + meta converter | |
# | |
# Output into relative JPEG directory | |
# | |
# Requires: dcraw, cjpeg, exiv2 | |
# any argument means verbose... | |
if [ ${#} -ne 0 ]; then | |
VERBOSE=1 | |
else | |
VERBOSE=0 | |
fi | |
CPU_COUNT=$(getconf _NPROCESSORS_ONLN) | |
RUNNINGJOBS=0 | |
find . -type f -iregex ".*\.\(ARW\|CR2\|CRW\|DCR\|DNG\|FPX\|MRW\|NEF\|ORF\|PCD\|PTX\|RAF\|RAW\|RW2\)$" -print0 | while IFS= read -r -d $'\0' line; do | |
FILENAME="${line##*/}" | |
FILENAME="${FILENAME%.*}" | |
JPEGNAME="${FILENAME}.jpg" | |
INPATH="${line%/*}" | |
OUTPATH="${INPATH}/JPEG" | |
OUTFILE="${OUTPATH}/${JPEGNAME}" | |
if [ ! -d "${OUTPATH}" ]; then | |
mkdir -p "${OUTPATH}" | |
fi | |
if [ -s ${OUTFILE} ]; then | |
continue | |
fi | |
( \ | |
dcraw -a -c "$line" | \ | |
cjpeg -quality 95 -optimize -progressive > "${OUTFILE}" && \ | |
exiv2 ex "$line" && \ | |
mv "${INPATH}/${FILENAME}.exv" "${OUTPATH}/" && \ | |
exiv2 in "${OUTFILE}" && \ | |
rm "${OUTPATH}/${FILENAME}.exv" && \ | |
exiv2 -T mv "${OUTFILE}" \ | |
) & | |
RUNNINGJOBS=$(( $RUNNINGJOBS+1 )) | |
if [ "$VERBOSE" -ne 1 ]; then | |
echo -n "$RUNNINGJOBS" | |
else | |
printf "${line}\t->\t${OUTFILE}\n" | |
fi | |
[ "$VERBOSE" -ne 1 ] && echo -n "." | |
if [ "$RUNNINGJOBS" -eq "$CPU_COUNT" ]; then | |
wait | |
RUNNINGJOBS=0 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment