#!/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="-filter_complex scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2" HWENCODE="-hwaccel auto" SILENT="-loglevel quiet -stats" if [[ "${BUG}" != "" ]]; then SCALE="-i ${BUG} -filter_complex [0]scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2,overlay=x=0:y=0[out] -map [out]" fi Encode () { name=$(basename "${1}") nameNoExt=${name%.*} now=$(date '+%s') output="${VIDEOS}/${nameNoExt}_${now}.mkv" #echo $output if [ -f "${VIDEOS}/${nameNoExt}"*".mkv" ]; then echo "File ${name} already exists" return fi echo "Encoding ${name}..." if [[ "${name}" == *".jpg" ]] || [[ "${name}" == *".jpeg" ]] || [[ "${name}" == *".png" ]]; then ffmpeg -nostdin -loop 1 -t 30 -i "${1}" ${SCALE} -c:v libx264 -tune zerolatency -pix_fmt yuv420p -r 30 -t 30 \ -an ${SILENT} \ "${output}" else ffmpeg -nostdin ${HWENCODE} -i "${1}" ${SCALE} -c:v libx264 -tune zerolatency -pix_fmt yuv420p \ -c:a aac -b:a 190k -ac 2 -ar 44100 \ -f flv ${SILENT} "${output}" fi } fileList=$(mktemp) ls -1 "${INPUT}/" > "${fileList}" while read videoIn; do Encode "${INPUT}/${videoIn}" done < "${fileList}" rm -f "${fileList}"