Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created Oct 14, 2016
Embed
What would you like to do?
#!/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