#!/bin/bash -e

#####################################################
#
# This script will take an audio file and an image and
# combine them to create a video. 
#
# Usage: bash ffmpeg/audio/stillaudio.sh <input audio> <input image> <output video>
#
#####################################################

AUDIO="${1}"
IMAGE="${2}"
OUTPUT="${3}"

# Check if file extension is .mkv or .MKV
if [[ "${OUTPUT}" != *".mkv" ]]; then
	echo "Please use an .mkv extension on your output file argument"
	exit 1
fi

ffmpeg -loop 1 \
	-framerate 2 \
	-i "${IMAGE}" \
	-i "${AUDIO}" \
	-c:v libx264 \
	-preset slow \
	-tune stillimage \
	-pix_fmt yuv420p \
	-crf 12 \
	-vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" \
	-c:a aac \
	-b:a 192k \
	-shortest \
	"${OUTPUT}"