feat(us/bk-copy-rand-music.sh):Add script
[BK-2020-03.git] / unitproc / bktemp-get_media_length
diff --git a/unitproc/bktemp-get_media_length b/unitproc/bktemp-get_media_length
new file mode 100644 (file)
index 0000000..76c8f3d
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+get_media_length() {
+    # Use ffprobe to get media container length in seconds (float)
+    # Usage: get_media_length arg1
+    # Input:  arg1: path to file
+    # Output: stdout: seconds (float)
+    # Depends: ffprobe 4.1.8
+    # Ref/Attrib: [1] How to get video duration in seconds? https://superuser.com/a/945604
+    local file_in
+    file_in="$1";
+    if [[ ! -f $file_in ]]; then
+       die "ERROR:Not a file:$file_in";
+    fi;
+    ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file_in";
+} # Get media container length in seconds via stdout
+
+# Author: Steven Baltakatei Sandoval
+# License: GPLv3+
\ No newline at end of file