Skip to content

Instantly share code, notes, and snippets.

@mikeflynn
Created January 31, 2025 21:57
Show Gist options
  • Save mikeflynn/da8cb20c2564a8a75ff46b7eb1000a55 to your computer and use it in GitHub Desktop.
Save mikeflynn/da8cb20c2564a8a75ff46b7eb1000a55 to your computer and use it in GitHub Desktop.
A bash script to split audio by a list of given time codes
#!/usr/bin/env bash
INPUT=$1
INPUT_FILE="${INPUT%.*}"
TIMES=$2
IFS=',' read -ra start_times <<< "$TIMES"
idx=0
ffmpeg -i $INPUT \
$(for i in "${start_times[@]}"; do
idx=$((idx+1))
next_start="${start_times[$idx]}";
if [[ -z "$next_start" ]]; then # Last track
duration=$(ffprobe $INPUT -show_entries format=duration -sexagesimal -v quiet -of csv="p=0");
else
duration="$next_start"
fi
output="${INPUT_FILE}_$idx.mp3";
echo "-ss $i -t $duration -c copy $output";
done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment