#!/usr/bin/env bash # 26.03.04 :: klevstul rotate() { test_integer() { if ! [[ $1 =~ ^[123]$ ]]; then echo "error: variable (times to rotate) must be 1, 2, or 3" exit 1 fi } filename=$1 # ~/syncDir/0_downloads/frodeKlevstul.jpg extension="${filename##*.}" # jpg basename_without_ext="${filename%.*}" # ~/syncDir/0_downloads/frodeKlevstul basename_only="${basename_without_ext##*/}" # frodeKlevstul times_to_rotate=$2 # how many times to rotate 90 degrees times_to_rotate=${times_to_rotate:=1} # set to 1 if no value is given test_integer ${times_to_rotate} # make sure the input (if given from the user) is valid transpose="transpose=1" # add a transpose for each time to rotate for ((i = 2; i <= ${times_to_rotate}; i++)); do transpose+=",transpose=1" done # 90 degrees clockwise: transpose=1 # 90 degrees counterclockwise: transpose=2 # `-c:a copy` - ensures audio (if present) is copied without re-encoding (not applicable for images, but safe to include). ffmpeg -i ${filename} -vf ${transpose} -c:a copy ${basename_without_ext}_rot.${extension} } this_file_name=`basename "$0"` if [ $# -lt 1 ]; then echo "error: path to file is missing." echo "usage: '$this_file_name [path_to_file] ([times_to_rotate_90_degrees (1)])'" exit 1 fi rotate $1 $2