#!/bin/bash

#
#  Singe 2
#  Copyright (C) 2006-2020 Scott Duensing <scott@kangaroopunch.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

G_OUTPATH=$1

G_L="-------------------------------------------------------------------------------"
for V in *.m2v; do
	F="${V%.*}"
	echo ${G_L}
	echo Working on ${G_OUTPATH}${F}...
	echo ${G_L}
	if [[ ! -f ${G_OUTPATH}${F}.mkv ]]; then
		if [[ -f ${F}.ogg ]]; then
			ffmpeg -hide_banner -loglevel error -stats -i ${F}.m2v -i ${F}.ogg -c:v libx264 -c:a aac -strict experimental ${G_OUTPATH}${F}.mkv
		else
			ffmpeg -hide_banner -loglevel error -stats -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i ${F}.m2v -shortest -c:v libx264 -c:a aac -strict experimental ${G_OUTPATH}${F}.mkv
		fi
	fi
done
