Skip to content

Instantly share code, notes, and snippets.

@thealanberman
Last active August 7, 2019 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thealanberman/b63ace5d2a45bab1bbba54674c239f50 to your computer and use it in GitHub Desktop.
Save thealanberman/b63ace5d2a45bab1bbba54674c239f50 to your computer and use it in GitHub Desktop.
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