Added parallel processing using xargs. Set your CONCURRENCY_LEVEL

accordingly!
This commit is contained in:
Markus Birth 2015-05-04 00:28:53 +02:00
parent 4f7db4b072
commit 4011da5b0c
2 changed files with 53 additions and 33 deletions

View File

@ -1,6 +1,5 @@
#!/bin/bash
# @author Markus Birth <markus@birth-online.de>
# Needs: Hugin (nona), exiv2, sed, realpath
if [ "$#" = "0" ]; then
echo "RICOH Theta to PhotoSphere converter"
@ -8,38 +7,17 @@ if [ "$#" = "0" ]; then
exit 1
fi
while [ "$#" -gt 0 ]; do
REALNAME=`realpath "$1"`
BASENAME=`echo "$REALNAME" | sed -nre 's/^(.*)\.[^.]+$/\1/p'`
OUTNAME="${BASENAME}_xmp.jpg"
shift
echo "Input : $REALNAME ($# more left)"
echo "Output: $OUTNAME"
if [ -z "$CONCURRENCY_LEVEL" ]; then
CONCURRENCY_LEVEL=1
fi
if [ -f "$OUTNAME" ]; then
echo "Output file already exists. Skipping..."
continue
fi
SCRIPTREAL=`realpath "$0"`
SCRIPTHELPER=`echo "$SCRIPTREAL" | sed -nre 's/^(.*)\.sh$/\1_single.sh/p'`
INFO=`exiv2 -pa "$REALNAME" | grep "Pose.*Degrees"`
PITCH=`echo "$INFO" | grep "Pitch" | sed -nre 's/^.* ([0-9.-]+)$/\1/p'`
ROLL=`echo "$INFO" | grep "Roll" | sed -nre 's/^.* ([0-9.-]+)$/\1/p'`
if [ ! -f "$SCRIPTHELPER" ]; then
echo "ERROR: Helper script missing!"
echo "Make sure it exists as: $SCRIPTHELPER"
exit 2
fi
echo "Pitch / Roll: $PITCH / $ROLL"
if [ -z "$PITCH" -o "$PITCH" == "0" -o -z "$ROLL" -o "$ROLL" == "0" ]; then
echo "No pitch/roll info found or already zero. No processing neccessary."
continue
fi
# echo "i w3584 h1792 f4 v360 r$ROLL p$PITCH y0 n\"$REALNAME\"" > "$BASENAME.pto"
# echo "p w3584 h1792 f2 v360 r0 p0 y0 n\"JPEG q99\"" >> "$BASENAME.pto"
# nona -o "$OUTNAME" "$BASENAME.pto"
# rm "$BASENAME.pto"
echo -e "i w3584 h1792 f4 v360 r$ROLL p$PITCH y0 n\"$REALNAME\"\np w3584 h1792 f2 v360 r0 p0 y0 n\"JPEG q99\"" | nona -g -o "$OUTNAME" /dev/stdin
exiv2 ex "$REALNAME"
mv "$BASENAME.exv" "${BASENAME}_xmp.exv"
exiv2 in -M "reg GPano http://ns.google.com/photos/1.0/panorama/" -M "set Xmp.GPano.PosePitchDegrees 0" -M "set Xmp.GPano.PoseRollDegrees 0" "${BASENAME}_xmp.jpg"
rm "${BASENAME}_xmp.exv"
done
find "$@" -print0 | xargs -0 -P $CONCURRENCY_LEVEL -n 1 -I {} $SCRIPTHELPER "{}"

42
convert_single.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
# @author Markus Birth <markus@birth-online.de>
# Needs: Hugin (nona), exiv2, sed, realpath
if [ -f "$1" ]; then
REALNAME=`realpath "$1"`
BASENAME=`echo "$REALNAME" | sed -nre 's/^(.*)\.[^.]+$/\1/p'`
OUTNAME="${BASENAME}_xmp.jpg"
echo "Input : $REALNAME"
echo "Output: $OUTNAME"
if [ -f "$OUTNAME" ]; then
echo "Output file already exists. Skipping..."
exit 1
fi
INFO=`exiv2 -pa "$REALNAME" | grep "Pose.*Degrees"`
PITCH=`echo "$INFO" | grep "Pitch" | sed -nre 's/^.* ([0-9.-]+)$/\1/p'`
ROLL=`echo "$INFO" | grep "Roll" | sed -nre 's/^.* ([0-9.-]+)$/\1/p'`
echo "Pitch / Roll: $PITCH / $ROLL"
if [ -z "$PITCH" -o "$PITCH" == "0" -o -z "$ROLL" -o "$ROLL" == "0" ]; then
echo "No pitch/roll info found or already zero. No processing neccessary."
exit 2
fi
# echo "i w3584 h1792 f4 v360 r$ROLL p$PITCH y0 n\"$REALNAME\"" > "$BASENAME.pto"
# echo "p w3584 h1792 f2 v360 r0 p0 y0 n\"JPEG q99\"" >> "$BASENAME.pto"
# nona -o "$OUTNAME" "$BASENAME.pto"
# rm "$BASENAME.pto"
echo -e "i w3584 h1792 f4 v360 r$ROLL p$PITCH y0 n\"$REALNAME\"\np w3584 h1792 f2 v360 r0 p0 y0 n\"JPEG q99\"" | nona -g -o "$OUTNAME" /dev/stdin
exiv2 ex "$REALNAME"
mv "$BASENAME.exv" "${BASENAME}_xmp.exv"
exiv2 in -M "reg GPano http://ns.google.com/photos/1.0/panorama/" -M "set Xmp.GPano.PosePitchDegrees 0" -M "set Xmp.GPano.PoseRollDegrees 0" "${BASENAME}_xmp.jpg"
rm "${BASENAME}_xmp.exv"
else
echo "RICOH Theta to PhotoSphere converter"
echo "Usage: $0 file"
exit 3
fi