36

I am looking for a software in Linux, that will add the album-art/cover to each of the selected files in batch-mode. The album art is a jpg/png stored in my computer. It will be awesome if it can import from internet.

Currently I have tried both Rhythmbox and Banshee. I have also tried lame and easytag, but seems they do not support batch mode. lame is not adding the properties, but overwriting. (I know lame is the only command line s/w i have used so far).

So, basically I am looking for:

<some magic s/w> --picture=<my chosen picture> Music/Artist/*.mp3

That will add the picture to the metadata of the file, permanently.

Can you suggest me any such software?

23

lame

Using lame you can do this using a little scripting:

$ lame --ti /path/to/file.jpg audio.mp3

If the files are named something like this you can make a shell script to do what you want:

for i in file1.mp3 file2.mp3 file3.mp3; do
  albart=$(echo $i | sed 's/.mp3/.jpg/')
  lame --ti /path/to/$albart $i
done

You can make the above slightly more compact and eliminate the need for sed by using bash to do it by having it remove the matching suffix:

...
albart="${i%.mp3}.jpg"
...

Picard/MusicBrainz

If you want to do this on a large scale I'd suggest using Picard which is the frontend tool for using the MusicBrainz database. There is a plugin to Picard called "Cover Art Downloader", which can do this to batches of your collection.

The above doesn't appear to be command line driven however.

beets

Another option would be to use beets. This can be driven from the command-line and makes use of MusicBrainz database for sourcing the album art.

You can either source the album art usingFetchArt Plugin or embed it using the EmbedArt Plugin.

Other options?

Also take a look at this previously asked U&L Q&A titled: Which mp3 tagging tool for Linux?. There are several alternative tools listed in this thread.

  • You can avoid the sed call with something like albart="${i%.mp3}.jpg". More importantly, I just tested your lame command and got lame: unrecognized option -i... – evilsoup Jul 30 '13 at 23:09
  • @evilsoup - thanks, the switch was missing a dash. Should be --ti ... – slm Jul 30 '13 at 23:15
  • @evilsoup - also added your feedback on not using sed. Thanks! – slm Jul 30 '13 at 23:24
  • Is it possible to remove the cover art with lame, too? – Exeleration-G Dec 9 '13 at 10:09
  • 7
    @Exeleration-G - no I wouldn't recommend using lame since it's actually an encoder. There are other tools for just manipulating the id3 tags of an mp3. You can use id3v2 -r "APIC" *.mp3 or eyeD3 --remove-all-images *.mp3 to remove any attached images. – slm Dec 9 '13 at 13:34
17

One solution would be to use ffmpeg:

ffmpeg -i input.mp3 -i cover.jpg -map_metadata 0 -map 0 -map 1 output.mp3

You can put this in a for loop to do every MP3 in a directory:

for f in ./*.mp3; do ffmpeg -i "$f" -i cover.jpg -map_metadata 0 -map 0 -map 1 out-"${f#./}"; done

This will create a separate output file (so if you have a file called foo.mp3, you will end up with both foo.mp3 and out-foo.mp3); this is because ffmpeg cannot write over its input. You can fix this with something like:

for f in ./*.mp3; do \
ffmpeg -i "$f" -i cover.jpg -map_metadata 0 -map 0 -map 1 out-"${f#./}" \
&& mv out-"${f#./}" "$f"; done

Using ffmpeg for this problem is a little bit like using a cruise missile to crack a nut. More specialised metadata-manipulating tools will certainly be able to do this in a cleaner, shorter command.

  • 6
    The ffmpeg command shown here will encode the audio. If you're converting from another format, that's fine, but if you just want to add art to an existing mp3 without re-encoding it, add -acodec copy after the -map 1. – jsd Mar 24 '15 at 18:39
  • This isn't working for me, any particular reason? I only get the mp3 file but no thumbnail. @jsd – Chef Pharaoh Aug 14 '16 at 22:13
  • Sorry @ChefPharaoh I don't know why it isn't working for you. I just tried doing wav->mp3 while adding art, and just adding art to an existing mp3 with those ffmpeg commands shown above. Both times it worked fine. – jsd Aug 15 '16 at 16:51
  • @evilsoup I'm not sure if I am doing something super evil or wrong, but I am able to modify my mp3 files in place using process substitution. Kinda simplifies this script and it seems to be super fast. – rien333 Oct 30 '18 at 12:26
  • Worked like a treat, and I also found ffmpeg to be slightly faster than lame :) – Tina Mar 5 at 1:11
6

For MP3:

eyeD3 --add-image="cover.jpg":FRONT_COVER "file.mp3"

For FLAC:

metaflac --import-picture-from="cover.jpg" "file.flac"

OGG/Vorbis seems to be more complicated.

5

You can use FancyAudio gem for this. It can add album art to mp3 files. Documentation is available here.

features

  1. add album art to single mp3 file
  2. add album art to multiple mp3 files.

Below screen shot shows the output of fancy_audio when run in a folder containing an image and multiple mp3 files

enter image description here

Below screen shot shows the output of fancy_audio when run in a folder containing mp3 and image files

This image shows the output of fancy_audio when run in a folder containing mp3 and image files

  • This is easy, and works faster than lame when adding the same image to multiple mp3 files. You don't need to know Ruby ;) - this is a standalone script. – Tomasz Gandor Jan 29 '17 at 23:44
0

OP states that he would prefer if the cover is downloaded from the web, and I just wrote a pretty okay script for that using eye3D and sacad, both installable from pip. eye3D is very useful for this purpose as it doesn't seem to re-encode audio and using the --to-v2.4 flag handles any mp3 files, no matter the type of id3 tag. The script should be launched from the directory that contains the mp3 files. It can be run with no arguments, guessing the artist and album name from the id3 tags, or with manual names as arguments, e.g. embedart "pink floyd" "dark side of the moon". It's written for the fish shell, but should easily be portable to bash if you change all the set commands to bash variable assigments.

function embedart
    if echo $argv | grep -q -e '-h'
       echo 'embedart "[Artist]" "[Album]"'
       return
    end

    if test $argv[1]
        set artist $argv[1]
        set album $argv[2]
    else
        set artist (eyed3 (ls *mp3 | head -1) | ggrep -oP "artist.*: \K.*" | head -1)
        if not test $artist
            echo "No artist found!"
            return
        end
        set album (eyed3 (ls *mp3 | head -1) | ggrep -oP "album.*: \K.*" | head -1)
        if not test $album
            echo "No album found!"
            return
        end
    end

    sacad $artist $album 350 cover.jpg -v warning 2> /dev/null > /dev/null
    eyeD3 --to-v2.4 --add-image "cover.jpg:FRONT_COVER" *mp3 -Q 2> /dev/null > /dev/null

    rm cover.jpg
    echo "Done!"
end
-1

eyeD3 does not work with Unicode. If any non-ascii characters are in the .mp3 file name (or even in just an ancestor directory name, such as the Album directory), then it aborts. LTA.

So you are out of luck if the Album or Song title is not written in English!

For example:

cp yoursong.mp3 /tmp/Странджанска.mp3
eyeD3 --add-image folder.jpg:FRONT_COVER Странджанска.mp3

Apparently eyeD3 wants to put the full path of the .mp3 file inside the .mp3 file and can't handle non-ascii characters.

Uncaught exception: 'ascii' codec can't encode characters in position 5-16: ordinal not in range(128)
eyed3:ERROR: 'ascii' codec can't encode characters in position 5-16: ordinal not in range(128)
Traceback 
...(long traceback omitted)...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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