#!/bin/bash
#                       /usr/local/bin/audio_to_mp4
# https://crystalfaeries.net/posix/bin/audio_to_mp4
# celeste@crystalfaeries.net AUDIO_TO_MP4 2021-03-15 23:18:32+00:00
# Convert audios & an image to MP4 videos using ffmpeg [All commands]
# First argument is path to the image, subsequent are source audio's
# Default output is to /video/`whoami`/

still="${1}"
if [ "${still}" == "" ]
then
		echo -n "$0: accepting null first argument (path to the still image to embed with the music); defaulting to "	2>1
		still="/imgs/celeste/landscape/celeste_crystalfaery.2016-06-02.18-02.cropped.png"
		echo "${still}"	2>1
else
	if [ -s "${still}" ]
	then		# seems to be a file there
		:	# we got some argument, is it a non-zero file?
	else
		echo -n "$0: accepting null file specified as first argument (path to the still image to embed with the music); defaulting to "	2>1
		still="/imgs/celeste/landscape/celeste_crystalfaery.2016-06-02.18-02.cropped.png"
		echo "${still}"	2>1
	fi
fi
shift	# toss the first argument now that we have specified or default image file
for soundfile in "$@"
do
	ffmpeg -loop 1 -i "${still}" -i "${soundfile}" -shortest -c:v libx264 -preset ultrafast -c:a copy "/video/`whoami`/${soundfile%.*}.mp4"	\
	||	exit $?	# abort on first error
done 
exit	$?	# should be a zero, yeah?

