#!/bin/bash

set -e

if [ -z "$3" ]; then
	cat <<- EOF
	Usage: slow-mo.sh /input.mp4 /outputm.mp4 RATE
	Alternative flags( environment variables ):
	    REMOVE_AUDIO
		    When this is set the audio output is disabled
		SLOW_RATE
		    2.0 => Half speed
            3.0 => 3x slower
            Formula is 1 / RATE => OutputRate
	EOF
	exit 0
fi

# If this gets set then we do not create the first clip with audio
# Default to having no audio
if [ ! -z "$REMOVE_AUDIO" ]; then
	echo "Audio: DISABLED"
	FFMPEG_COPY="-c copy -an"
else
	echo "Audio: ENABLED"
	FFMPEG_COPY="-c:v copy"
fi

# Aliasing input variables
input="$1"
output="$2"

SLOW_RATE=2.0
LOG="-loglevel error"

ffmpeg $LOG -y -i "$input" -vf "setpts=$SLOW_RATE*PTS" "$output"

