configs/arch-config/scripts/pieces/ffmpeg-transcode.sh

36 lines
733 B
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
set -euo pipefail
2021-07-24 16:59:43 +02:00
if [ $# -ne 3 ]; then
echo "Please use this script with \"PATH\" \"Input Extension\" \"Output Extension\""
2021-07-24 16:53:34 +02:00
$(exit 1); echo "$?"
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 "$?"