#!/bin/sh
# ffmpeg_batch_encode_dir.sh
# 2023-03-03
# by Gernot Walzl
# Encodes all video files in a directory using ffmpeg.
# Usage: ./ffmpeg_batch_encode_dir.sh INPUT_DIRECTORY OUTPUT_DIRECTORY
# VIDEOFILTER=${VIDEOFILTER:-'framestep=2,scale=1920:1080'}
VIDEOFILTER=${VIDEOFILTER:-'scale=1920:1080'}
DIR_IN=$1
DIR_OUT=$2
set -e
print_usage () {
echo "Usage: $0 INPUT_DIRECTORY OUTPUT_DIRECTORY"
exit 1
}
if [ -z "$DIR_IN" -o -z "$DIR_OUT" ]; then
print_usage
fi
if [ ! -d "$DIR_IN" ]; then
print_usage
fi
mkdir -p "$DIR_OUT"
find "$DIR_IN" -maxdepth 1 -iname '*.mp4' \
| while read INPUT; do
FILENAME=$(basename "$INPUT")
OUTPUT="${DIR_OUT}/${FILENAME}"
ffmpeg -nostdin -i "$INPUT" \
-vf "$VIDEOFILTER" \
-preset veryslow \
-movflags faststart "$OUTPUT"
done