Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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:

#!/bin/bash

set -e

for filename in "$@" ; do
    if [[ "$filename" == -* ]] ; then
        printf "Filename %s must not begin with a dash\n" "$filename" 1>&2
        continue
    fi
    printf "Converting %s\n" "$filename"
    filename=$(realpath "$filename")
    directory=$(mktemp -d)
    cwd=$(pwd)
    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" 
        break
    done
    shopt -u nullglob
    mv "$output" "$(dirname "$filename")"
    cd "$cwd"
    rm -r "$directory"
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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