2

I would like to use the function mutagen.mp4.MP4Cover(data, imageformat) (direct link to documentation), however the documentation only specifies imageformat, but not what data is.

I have a .png file that I would like to add to an .mp3 as cover/album art.

imrek
  • 2,930
  • 3
  • 20
  • 36

1 Answers1

1

"I have a .png file that I would like to add to an .mp3 as cover/album art."

Is this MP3 data actually contained inside an MP4 or M4A format file? If not, then you cannot use .mp4.MP4Cover since the header of MP3 file does have any "slot" to insert some cover art. Containers like MP4 & M4A have a specific place built-in for adding cover (the covr atom).

For a stand-alone MP3 file you must instead add ID3 metadata.
Specfically you want to add a tag called APIC (Attached PIC) :

from mutagen import id3, mp3
file = mp3.MP3('test.mp3')

imagedata = open('cover.png', 'rb').read()
file.tags.add(id3.APIC(3, 'image/png', 3, 'Front cover', imagedata))
file.save()
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • PS: I don't use Mutagen but I know MP3 & MP4 bytes so if the above code isn't wrking let me know of any errors. From research that code seemed as easiest example to share / test. – VC.One Mar 19 '17 at 16:45
  • Thank you I have figured out in the meantime that I was wrong with my approach and have solved the issue the same way you propose here. – imrek Mar 20 '17 at 13:13