Files
sam2/notebooks/rvm_split_seconds.sh
2024-10-21 19:49:59 -07:00

38 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Check if a file was dragged and dropped onto the script
if [ -z "$1" ]; then
echo "Drag and drop a video file onto this script to split it into segments."
read -p "Press [Enter] key to continue..."
exit 1
fi
# Prompt the user for the segment time in seconds
read -p "Time in seconds per segment: " time
# Set input file and output folder variables
input_file="$1"
output_folder="${input_file%.*}_segments"
# Create the output folder
mkdir -p "$output_folder"
# Split the video into segments using ffmpeg
ffmpeg -i "$input_file" -c copy -f segment -segment_time "$time" -reset_timestamps 1 "$output_folder/segment_%03d.mp4"
# Change to the output folder
cd "$output_folder"
# Create a file list for the segments and move each segment to its own folder
counter=0
for segment in segment_*.mp4; do
segment_folder="segment_$counter"
mkdir -p "$segment_folder"
mv "$segment" "$segment_folder/"
echo "file '$segment_folder/$segment'" >> file_list.txt
counter=$((counter + 1))
done
echo "Video has been split into segments."
read -p "Press [Enter] key to continue..."