I have some .mp4 and .m4a audio files that I want to convert to .mp3 files. I want the resulting .mp3 files to include the cover art included in the source files, without fiddling with EasyTAG manually. How can I do this?


I've written a script that will do this automatically. Just run the script against each .m4a or mp4 file, like this, and it will produce the .mp3 files in the same directory:

convert-mp4-to-mp3.sh *.mp4 *.m4a

You'll need to install these dependencies:

sudo apt-get install realpath libav-tools atomicparsley eyed3

Here's the script. Copy and paste this content and save it to a file named convert-mp4-to-mp3.sh:


set -e

for filename in "$@" ; do
    if [[ "$filename" == -* ]] ; then
        printf "Filename %s must not begin with a dash\n" "$filename" 1>&2
    printf "Converting %s\n" "$filename"
    filename=$(realpath "$filename")
    directory=$(mktemp -d)
    output="$(basename "$filename" | sed 's/\.[^.]*$//').mp3"
    cd "$directory"
    avconv -i "$filename" "$output"
    ln -s "$filename" "$(basename "$filename")"
    AtomicParsley "$(basename "$filename")" --extractPix || true
    shopt -s nullglob
    for imagefilename in *.jpg *.png *.JPG *.PNG ; do
        eyeD3 --add-image="$imagefilename":FRONT_COVER "$output" 
    shopt -u nullglob
    mv "$output" "$(dirname "$filename")"
    cd "$cwd"
    rm -r "$directory"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.