]> zdv2.bktei.com Git - BK-2020-03.git/commitdiff
feat(user/mp4_make_small.sh):Automate making shareable small videos
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 6 Jul 2026 23:12:09 +0000 (23:12 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Mon, 6 Jul 2026 23:12:09 +0000 (23:12 +0000)
user/mp4_make_480.sh [moved from user/mp4_make480.sh with 95% similarity, mode: 0755]
user/mp4_make_small.sh [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
similarity index 95%
rename from user/mp4_make480.sh
rename to user/mp4_make_480.sh
index 8799a2e..8652f1c
@@ -5,7 +5,7 @@
 #        arg2  dir  output dir (optional)
 # Output: dir   ./out/
 #         file  ./out/[files]_480.mp4
 #        arg2  dir  output dir (optional)
 # Output: dir   ./out/
 #         file  ./out/[files]_480.mp4
-# Version: 0.1.2
+# Version: 0.1.3
 # Depends: GNU parallel 20161222, ffmpeg 4.3.6-0
 # Ref/Attrb: [1]: FFmpeg wiki: https://trac.ffmpeg.org/wiki/Scaling
 declare -g dir_in dir_out;
 # Depends: GNU parallel 20161222, ffmpeg 4.3.6-0
 # Ref/Attrb: [1]: FFmpeg wiki: https://trac.ffmpeg.org/wiki/Scaling
 declare -g dir_in dir_out;
@@ -25,7 +25,7 @@ check_input() {
 };
 convert_video() {
     find "$dir_in" -mindepth 1 -maxdepth 1 -type f -iname "*.mp4" | \
 };
 convert_video() {
     find "$dir_in" -mindepth 1 -maxdepth 1 -type f -iname "*.mp4" | \
-        parallel job_ffmpeg "{}" "$path_out";
+        parallel -j25% job_ffmpeg "{}" "$path_out";
 };
 job_ffmpeg() {
     path_in="$1";
 };
 job_ffmpeg() {
     path_in="$1";
diff --git a/user/mp4_make_small.sh b/user/mp4_make_small.sh
new file mode 100755 (executable)
index 0000000..75346f4
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Desc: Reèˆncodes .mp4 videos in a specified directory to reduce size.
+# Usage: mp4_make480.sh [dir in] [dir out]
+# Input: arg1  dir  input dir
+#        arg2  dir  output dir (optional)
+# Output: dir   ./out/
+#         file  ./out/[files]_small.mp4
+# Version: 0.0.1
+# Depends: GNU parallel 20231122, ffmpeg 6.1.1
+# Ref/Attrb:
+declare -g dir_in dir_out;
+
+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_small";
+    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 -j25% job_ffmpeg "{}" "$path_out";
+};
+job_ffmpeg() {
+    path_in="$1";
+    path_out="$2";
+    file_in="$(basename "$path_in")";
+    path_out=./"$dir_out"/"${file_in%.[mM][pP]4}"_small.mp4;
+
+    declare -p path_in path_out file_in dir_out path_out opt_scale;
+    ffmpeg -nostdin -i "$path_in" -c:v libx264 -preset veryslow -crf 26 -pix_fmt yuv420p "$path_out";
+};
+export -f job_ffmpeg;
+
+main() {
+    check_input "$@";
+    convert_video;
+};
+
+main "$@";
+
+# Author: Steven Baltakatei Sandoval
+# License: GPLv3+