Embed album art in OGG through command line in linux
- by teratomata
I want to convert my music from flac to ogg, and currently oggenc does that perfectly except for album art. Metaflac can output album art, however there seems to be no command line tool to embed album art into ogg. MP3Tag and EasyTag are able to do it, and there is a specification for it here which calls for the image to be base64 encoded. However so far I have been unsuccessful in being able to take an image file, converting it to base64 and embedding it into an ogg file.
If I take a base64 encoded image from an ogg file that already has the image embedded, I can easily embed it into another image using vorbiscomment:
vorbiscomment -l withimage.ogg > textfile
vorbiscomment -c textfile noimage.ogg
My problem is taking something like a jpeg and converting it to base64. Currently I have:
base64 --wrap=0 ./image.jpg
Which gives me the image file converted to base64, using vorbiscomment and following the tagging rules, I can embed that into an ogg file like so:
echo "METADATA_BLOCK_PICTURE=$(base64 --wrap=0 ./image.jpg)" > ./folder.txt
vorbiscomment -c textfile noimage.ogg
However this gives me an ogg whose image does not work properly. I noticed when comparing the base64 strings that all properly embedding pictures have a header line but all the base64 strings I generate are lacking this header. Further analysis of the header:
od -c header.txt
0000000 \0 \0 \0 003 \0 \0 \0 \n i m a g e / j p
0000020 e g \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000040 \0 \0 \0 \0 \0 \0 \0 \0 035 332
0000052
Which follows the spec given above. Notice 003 corresponds to front cover and image/jpeg is the mime type.
So finally, my question is, how can I base64 encode a file and generate this header along with it for embedding into an ogg file?