chore(user/mw_get_audiobook_chapters.sh):Clean up desc
[BK-2020-03.git] / user / mp4_make480.sh
CommitLineData
27c0d929
SBS
1#!/bin/bash
2# Desc: Reèˆncodes .mp4 videos in a specified directory.
42e88e4d
SBS
3# Usage: mp4_make480.sh [dir in] [dir out]
4# Input: arg1 dir input dir
5# arg2 dir output dir (optional)
27c0d929
SBS
6# Output: dir ./out/
7# file ./out/[files]_480.mp4
8e83a444 8# Version: 0.1.2
42e88e4d
SBS
9# Depends: GNU parallel 20161222, ffmpeg 4.3.6-0
10# Ref/Attrb: [1]: FFmpeg wiki: https://trac.ffmpeg.org/wiki/Scaling
11declare -g dir_in dir_out;
27c0d929 12
42e88e4d
SBS
13check_input() {
14 dir_in="$1";
15 if [[ $# -le 0 ]]; then echo "FATAL:Insufficient args:$#" 1>&2; exit 1; fi;
16 if [[ $# -eq 2 ]]; then
17 dir_out="$2";
18 else
19 dir_out="./out_480";
20 fi;
21 export dir_out;
22 if [[ ! -d "$dir_in" ]]; then echo "FATAL:Not a dir:$dir_in" 1>&2; exit 1; fi;
23 mkdir -p "$dir_out";
24 declare -p dir_in dir_out; # debug
25};
26convert_video() {
35ccc769 27 find "$dir_in" -mindepth 1 -maxdepth 1 -type f -iname "*.mp4" | \
42e88e4d
SBS
28 parallel job_ffmpeg "{}" "$path_out";
29};
30job_ffmpeg() {
31 path_in="$1";
32 path_out="$2";
33 file_in="$(basename "$path_in")";
34 path_out=./"$dir_out"/"${file_in%.mp4}"_480.mp4;
35 opt_scale="scale=-2:480"; # See [1]
36 declare -p path_in path_out file_in dir_out path_out opt_scale;
8e83a444 37 ffmpeg -nostdin -i "$path_in" -vf "$opt_scale" "$path_out";
42e88e4d
SBS
38};
39export -f job_ffmpeg;
27c0d929 40
42e88e4d
SBS
41main() {
42 check_input "$@";
43 convert_video;
44};
45
46main "$@";
47
48# Author: Steven Baltakatei Sandoval
49# License: GPLv3+