#!/bin/bash set -e source ./common.sh count=$(ls -1 "${INPUT}/" | wc -l) if [ ${count} == 0 ]; then echo "No files to process" exit 1 fi SCALE="scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2" Encode () { name=$(basename "${1}") nameNoExt=${name%.*} now=$(date '+%s') output="${VIDEOS}/${nameNoExt}_${now}.flv" if [ -f "${VIDEOS}/${nameNoExt}"*".flv" ]; then echo "File ${name} already exists" return fi echo "Encoding ${name}..." ffmpeg -i "${1}" -c:v libx264 -tune zerolatency -pix_fmt yuv420p -vf "${SCALE}" \ -c:a aac -b:a 190k -ac 2 -ar 44100 \ -f flv "${output}" } fileList=$(mktemp) ls -1 "${INPUT}/" > "${fileList}" while read videoIn; do Encode "${INPUT}/${videoIn}" done < "${fileList}" rm -f "${fileList}"