Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helps split a full album audio file into individual tracks with FFmpeg
#!/usr/bin/env bash
# set -euxo pipefail # uncomment this for debugging
###################################
# INSTRUCTIONS
# 1. Set Artist, Album, Timestamps and Track Names below
# 2. Save split.sh into the folder with file to be split
# 3. ./split.sh <m4a file to be split>
###################################
artist="The Artist"
album="My Album"
# Timestamps are in seconds
# start_time;end_time;song_title
timestamps=$(cat << EOF
0;300;First Song
302;600;Second Song
602;900;Third Song
902;1200;Fourth Song
EOF
)
###################################
# DO NOT EDIT BELOW HERE
###################################
mkdir -p "${artist}/${album}"
track=1
while read -r name
do
IFS=";" read -ra fields <<<"${name}"
startpos=${fields[0]}
endpos=${fields[1]}
title=${fields[2]}
length=$(( endpos-startpos ))
tr=$(printf "%02d" ${track})
ffmpeg -nostdin \
-ss "${startpos}" \
-i "${1}" -vn -c copy \
-t "${length}" \
-metadata title="${title}" \
-metadata artist="${artist}" \
-metadata track="${track}" \
-metadata album="${album}" \
-metadata album_artist="${artist}" \
"${artist}/${album}/${tr} ${title}.m4a"
(( "track++" ))
done <<< "${timestamps}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment