2021-04-25 14:51:25 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-07-24 16:59:43 +02:00
|
|
|
if [ $# -ne 3 ]; then
|
2021-04-25 14:51:25 +02:00
|
|
|
echo "Please use this script with \"PATH\" \"Input Extension\" \"Output Extension\""
|
2021-07-24 16:53:34 +02:00
|
|
|
$(exit 1); echo "$?"
|
2021-04-25 14:51:25 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO argument sanity check
|
|
|
|
|
|
|
|
dir=$1
|
|
|
|
inext=$2
|
|
|
|
outext=$3
|
|
|
|
numjobs=4
|
|
|
|
|
|
|
|
# go to target dir
|
|
|
|
cd "$dir"
|
|
|
|
|
|
|
|
# select all files
|
|
|
|
readarray -d '' infiles < <(find . -name "*\.$inext" -print0)
|
|
|
|
|
|
|
|
for file in "${infiles[@]}"; do
|
|
|
|
# only run $numjobs
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
# filename
|
|
|
|
file="$(basename "$file")"
|
|
|
|
# no extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# new extension
|
|
|
|
outextfile="${noextfile}.${outext}"
|
|
|
|
# actually use ffmpeg
|
|
|
|
ffmpeg -nostdin -i "$file" "${outextfile}" &
|
|
|
|
done
|
|
|
|
|
|
|
|
$(exit 0); echo "$?"
|