Scott Hanselman

Automating Adding iTunes Album Art to MP3 ID3 tags from the Command Line in C#

April 18, 2007 Comment on this post [6] Posted in Podcast | Programming | Tools
Sponsored By

It's been bugging me that the album art for my podcast doesn't appear in Windows Media Player, iTunes, or in iPods.

I assumed, incorrectly, that this was an iTunes meta-tagging problem, but then I realized that this was an MP3 problem, not an AAC or WMA problem, although both formats support adding art to the file.

The ID3 format is pretty extensive. You can put a great deal of meta-information into an MP3. The Attached picture or APIC "Frame" in ID lets you embed in PNGs or JPGs, along with their respective mime/types. 

I googled around over lunch and couldn't find a simple, free, command-line program that would let me easily add pictures to not only the existing MP3s for our show on the server-side, but also could be integrated into our existing audio file production workflow.

I ended up finding this great little library from 2004 called the tagnetlib project source was offered for free from the Nancy Street Blog. I converted it to .NET 2.0.

Now, note that the tagnetlib project is currently deprecated in lieu of the NTag product that Greg Keogh started in 2005 and released in May of 2006. The NTag project is much more interesting and appears to be well thought-out. He intends to support WMA and OGG and turn the project info a "Meta Tag Tagging" project that would support all popular audio formats.

I used the Tagnetlib because it was quick, incredibly easy, and I only had my lunch hour to do this. However, he's pretty clear that Tagnetlib is, again, totally deprecated and unsupported. Perhaps one day I'll get to spend more time with the NTag library. For now, my little hack is used like this:

embedid3.exe file.mp3 file.jpg [optionally "mime/type", default is "image/jpeg"]

Disclaimer: This app does one thing. It adds images to MP3 files that don't have them. It has no error handling or checking and it doesn't care about you or your MP3 collection. Don't even think about running it over your collection or using it for any purpose. It's useful for one thing. It's useful to me. Your Mileage WILL Vary. You have been warned.

Do make sure you checkout NTag and what Greg's working on over there. It's really pretty fun code to read.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
April 18, 2007 4:00
REally great tip. I miss having album artwork for all my mp3s!
April 18, 2007 10:52
Scott, been listening to your podcast since the beginning - it's awesome. The ratio of BS to useful content is second to none. I do tend to get most podcasts in the AAC format, mostly because it allows me to play some podcasts where the show host talks slowly at double speed on my iPod. Unfortunately, the AAC feeds from pwop have absolutely on identifying information (e.g. the AAC equivalent of ID3 tag). I hope this utility starts pwop on the road to fixing this problem.
April 18, 2007 19:03
If you don't need to automate it (like if you aren't scripting a complex set of these things or making it part of a "build process"), you can also just drag the appropriate image into the "album art" window in iTunes and iTunes will embed it into the track for you. You can even highlight several tracks and drag/drop the image one time to have it assigned to each selected track (which is a great/easy way to do complete albums all at once).
April 18, 2007 21:14
The best code is the code you don't have to write -- if you want to embed graphics into MP3s with minimum fuss, MediaMonkey FTW!

http://www.mediamonkey.com/
April 18, 2007 21:15
But, Jeff, I had fun writing it!
April 19, 2007 2:59
Hi Scott,

Like you, I was annoyed that some of my MP3s were missing their album artwork, and also like you, I'm a PowerShell fan. I started writing my own ID3 library a while a go but gave up when I found the Ultra ID3 library. This combined with a custom-written UltraID3.Format.ps1xml, and some handy aliases made the whole process of manipulating ID3 info (not just artwork) much easier.

http://home.fuse.net/honnert/hundred/UltraID3Lib/


TTFN,
Damian.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.