Skip to content

Instantly share code, notes, and snippets.

@cstroie
Created December 28, 2011 12:12

Revisions

  1. cstroie created this gist Dec 28, 2011.
    52 changes: 52 additions & 0 deletions recode.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/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 :