Skip to content

Instantly share code, notes, and snippets.

@mattconnell
Last active May 6, 2018 00:30
Show Gist options
  • Save mattconnell/d210a378643051d73def6d8704b2f2dc to your computer and use it in GitHub Desktop.
Save mattconnell/d210a378643051d73def6d8704b2f2dc to your computer and use it in GitHub Desktop.
Dumb shell script to sweep a directory for files of a certain extension and run them through ffmpeg to create mp3s. Used along with youtube-dl to bulk harvest music from various sources.
#!/bin/bash
set -e
### Setup
# List of formats to convert.
SOURCEFORMATS="m4a ogg opus"
# Desired outcome format
DESIREDFORMAT="mp3"
# Where to search?
FINDDIR="."
# Arguments to ffmpeg
FFMPEGARGS="-codec:a libmp3lame -qscale:a 0"
### Work
# For each format to seek and convert...
for i in ${SOURCEFORMATS} ; do
# Get a list of files matching the desired pattern.
FILES=$(find "${FINDDIR}" -type f -name "*.${i}")
# Iterate over those files, and convert them with ffmpeg.
echo "${FILES}" | while read -r f; do
#for f in ${FILES}; do
#NEWNAME=$(echo "${f}" | sed s/\."${i}"/."${DESIREDFORMAT}"/)
NEWNAME=${f//.${i}/.${DESIREDFORMAT}}
ffmpeg -i "${f}" ${FFMPEGARGS} "${NEWNAME}" < /dev/null
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment