-dir_in="$1";
-dir_out="./out";
-if [[ $# -ne 1 ]]; then echo "FATAL:No dir specified." 1>&2; exit 1; fi;
-if [[ ! -d "$dir_in" ]]; then echo "FATAL:Not a dir:$dir_in" 1>&2; exit 1; fi;
-mkdir -p "$dir_out";
-declare -p dir_in dir_out; # debug
+check_input() {
+ dir_in="$1";
+ if [[ $# -le 0 ]]; then echo "FATAL:Insufficient args:$#" 1>&2; exit 1; fi;
+ if [[ $# -eq 2 ]]; then
+ dir_out="$2";
+ else
+ dir_out="./out_480";
+ fi;
+ export dir_out;
+ if [[ ! -d "$dir_in" ]]; then echo "FATAL:Not a dir:$dir_in" 1>&2; exit 1; fi;
+ mkdir -p "$dir_out";
+ declare -p dir_in dir_out; # debug
+};
+convert_video() {
+ find "$dir_in" -mindepth 1 -maxdepth 1 -type f -iname "*.mp4" | \
+ parallel job_ffmpeg "{}" "$path_out";
+};
+job_ffmpeg() {
+ path_in="$1";
+ path_out="$2";
+ file_in="$(basename "$path_in")";
+ path_out=./"$dir_out"/"${file_in%.mp4}"_480.mp4;
+ opt_scale="scale=-2:480"; # See [1]
+ declare -p path_in path_out file_in dir_out path_out opt_scale;
+ ffmpeg -nostdin -i "$path_in" -vf "$opt_scale" "$path_out";
+};
+export -f job_ffmpeg;