Created
January 31, 2025 21:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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