Add album-art cover to mp3/ogg file from command-line in batch mode?

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.

  • MusicBrainz
  • Picard
  • Picard Plugins

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.

  • http://beets.radbox.org/

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.


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.


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.