I’m a software developer who runs Scribophile, an online writing group for serious writers, Writerfolio, an online writing portfolio service for freelancers, and Standard Ebooks, an open source project that produces liberated ebooks for the true book lover.

Adding album art to ogg files from the command line

I’ve recently been trying to script the process of transcoding some flac files to ogg. This is mostly a pretty smooth process, except for one hiccup: it seems that the command-line tools used to transcode music files don’t handle cover art for ogg files. All the other tags seem to be preserved, but not album art.

All the command-line tools used to edit ogg tags also don’t seem to handle album art. Some GUI tools, like MP3Tag, do handle cover art, but don’t have a command-line interface.

If you Google a solution to this you’ll get a wide variety of answers ranging from “base64 encode a jpg and insert it as a tag” to “ogg doesn’t support album art, sorry”. These are all wrong answers. In fact ogg does support album art, but base64 encoding isn’t enough. You have to use a certain tag and wrap the base64-encoded jpg in a special “frame”.

This isn’t something easily done by hand, but after spending a lot of time trawling for an easier solution, I came across a Stack Exchange post from user Biapy. They present part of a script from a larger toolset that adds cover art to ogg files.

I cleaned up and wrapped that script into an easy-to-use Bash script. You can download it here.

To use this script to add a cover image to an ogg file:

ogg-cover-art cover.jpg track.ogg

Comments

  1. Alice Wonder

    Thank you for this!

    I had to install a perl module I didn’t already have but other than that (which wasn’t a problem), the script works well in Fedora.

    Now if I can just figure out how to get cover art into opus files… unfortunately I haven’t yet found a CLI program that can modify opus files, but as they are in an ogg container and seem to be using vorbis style comments, I suspect this script can be adapted for opus once something similar to vorbiscomment exists for opus.

  2. Alice Wonder

    I was able to take that script and slightly modify it to add the metadata_block_picture as a comment to a flac file that opusenc copied over to the opus file (as does oggenc) when using the flac as source, resulting in the cover art working in the opus file 🙂

  3. Dick Whittington

    Thanks, your/Biapy’s script works well for me too.

    @Alice Wonder, as you may now be aware, I believe the opusenc Opus encoder now offers full support for album art with the —picture option:
    https://mf4.xiph.org/jenkins/view/opus/job/opus-tools/ws/man/opusenc.html

    This was added to Ubuntu since 14.04 LTS:
    http://manpages.ubuntu.com/manpages/trusty/man1/opusenc.1.html

    Still surprised there isn’t some kind of more official support for art in oggs, but this script does the job so that’s fine. Cheers.

  4. Gisela Herberts

    The script would be fine if not so platform dependent and audio oriented. On mac OS-X 10.6.8 there is no mimetype or base64 and cut supports different options. Such an important service like cover art for ogg files should work on all platforms. Thanks.

  5. Wild

    Many many thanks ! Good Job !

    Feature request :
    In documentation :
    — (https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE)
    — (https://xiph.org/flac/format.html#metadata_block_picture),

    APIC frame can be many type and i would like add some pictures in my files Ogg-Vorbis.

    Any chance to see a new flag to tell your script ? :


    ogg-cover-art 8 cover.png track.ogg