Skip to content

Instantly share code, notes, and snippets.

@non7top
Forked from cstroie/recode.sh
Created September 8, 2018 11:47
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 non7top/ed7eea8bc7c13570a0efb4db8fdaa9fa to your computer and use it in GitHub Desktop.
Save non7top/ed7eea8bc7c13570a0efb4db8fdaa9fa to your computer and use it in GitHub Desktop.
Recode MP3 files with normalization
#!/bin/bash
#
# recode
#
# Copyright 2011 Costin STROIE <costinstroie@eridu.eu.org>
#
# recode is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# recode is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with recode. If not, see <http://www.gnu.org/licenses/>.
#
# Recode audio files
WAVDIR="wav"
MP3DIR="mp3"
M4ADIR="m4a"
# Create dirs
[ -d "${WAVDIR}" ] || mkdir "${WAVDIR}"
[ -d "${MP3DIR}" ] || mkdir "${MP3DIR}"
[ -d "${M4ADIR}" ] || mkdir "${M4ADIR}"
for F in *.mp3
do
BN=`basename "$F" ".mp3"`
WAV="${WAVDIR}/${BN}.wav"
MP3="${MP3DIR}/${BN}.mp3"
M4A="${M4ADIR}/${BN}.m4a"
# Decode
madplay -o "${WAV}" "${F}"
# Normalize
normalize-audio -v "${WAV}"
# Encode to MP3
lame --preset standard "${WAV}" "${MP3}"
# Copy the ID3 tags
id3cp "${F}" "${MP3}"
# Encode to M4A
faac -w -s -o "${M4A}" "${WAV}"
# Remove the WAV file
rm -f "${WAV}"
done
# vim: set ft=sh ai ts=2 sts=2 et sw=2 sta nowrap nu :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment