python - There is an errors embed album art with mutagen? -
the problem is, whenever embed picture mp3 , mp3 file increase less bytes picture is. i'll explain in code:
import os mutagen.mp3 import mp3 mutagen.id3 import id3, apic, error mutagen import file audio = id3() open('111.mp3', 'rb') f: rawfile = f.read() dirpath, dirnames, filenames in os.walk('e:/exp/apic'): fname in filenames: path = os.path.join(dirpath, fname) ap = apic( encoding = 3, mime = 'image/jpg', type = 3, desc = u'cover', data = open(path, 'rb').read() ) sz_changed = os.stat('111.mp3').st_size audio.add(ap) audio.save('111.mp3') sz_changed = os.stat('111.mp3').st_size - sz_changed print u'lost bytes:%d' % (len(ap.data)-sz_changed) open('111.mp3', 'wb') f: f.write(rawfile) #reset
the code shows can't embed whole picture mp3 , neight mp3 player nor phone can read broken art problem is? although can embed pic when embed more larger pic.
now going show result of above code:
lost bytes:4174 lost bytes:5594 lost bytes:4924 lost bytes:4777 lost bytes:4938 lost bytes:4750 lost bytes:5558 lost bytes:4710 lost bytes:4924 lost bytes:5686 lost bytes:4936 lost bytes:4788 lost bytes:5319 lost bytes:5605 lost bytes:4790 lost bytes:4781 lost bytes:5692 lost bytes:5248
try changing:
mime = 'image/jpg' 'image/jpeg'
i had similar problem before , helped
Comments
Post a Comment