#!/bin/bash
set -e

mode="$1"
fn="$2"

[ -z "$2" ] && {
	echo "need arg 1: mode, [f]ast or [s]low"
	echo "need arg 2: filename"
	exit 1
}

args=()

[ "$mode" = f ] &&
	args=(-codec copy)

[ "$mode" = s ] &&
	args=(-vcodec rawvideo -acodec pcm_s16le)

[ -z "${args[*]}" ] && {
	echo "bad arg 1: $1"
	exit 1
}

nice ffmpeg -y -hide_banner -nostdin -v info -err_detect explode -xerror -i "$fn" "${args[@]}" -f null - &&
	rv=0 || rv=$?

[ $rv -eq 0 ] &&
	printf '\033[32mok\033[0m\n' ||
	printf '\033[1;37;41merror\033[0m\n'

exit $rv
