summaryrefslogtreecommitdiff
path: root/ar/.local/bin/cutvideo
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
commitc80a54e42b52ce297f0f2f71af23c562832025c7 (patch)
treedcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.local/bin/cutvideo
init
Diffstat (limited to 'ar/.local/bin/cutvideo')
-rwxr-xr-xar/.local/bin/cutvideo41
1 files changed, 41 insertions, 0 deletions
diff --git a/ar/.local/bin/cutvideo b/ar/.local/bin/cutvideo
new file mode 100755
index 0000000..3220008
--- /dev/null
+++ b/ar/.local/bin/cutvideo
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+usage() {
+ echo "Crop a video file using ffmpeg."
+ echo ""
+ echo "Usage: cutvideo [file_name] [position] [duration]"
+ echo ""
+ echo "Arguments:"
+ echo " file_name: The name of the video file (e.g., video.mp4)."
+ echo " position: The start position in the format HH:MM:SS (e.g., 00:00:00)."
+ echo " duration: The duration in seconds from the start position (e.g., 10)."
+ echo ""
+ echo "Example:"
+ echo " cutvideo ~/Video/video.mp4 00:01:00 10"
+ echo " This will create a 10-second cut starting at 00:01:00 in the video.mp4 file."
+ exit 1
+}
+
+[ -z "$1" ] && echo "Target file missing" && usage
+[ -z "$2" ] && echo "Target position missing" && usage
+[ -z "$3" ] && echo "Target duration missing" && usage
+
+file="$1"
+filename="${file%%.*}"
+ext="${file##*.}"
+num=1
+
+# Find a unique filename by incrementing num
+if [ -f "${filename}_cut.${ext}" ]; then
+ while [ -f "${filename}_cut_$(printf "%02d" "$num").${ext}" ]; do
+ num=$((num + 1))
+ done
+ new_filename="${filename}_cut_$(printf "%02d" "$num").${ext}"
+else
+ new_filename="${filename}_cut.${ext}"
+fi
+
+# Perform the cut using ffmpeg
+ffmpeg -hide_banner -ss "$2" -to "$3" -i "$file" -c copy "$new_filename"
+
+echo "Created file: $new_filename"