问题是,每当我将图片嵌入到 mp3 中时,该 mp3 文件总是比图片实际增加的字节少。我会用代码解释:
import os
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
from mutagen import File
audio = ID3()
with open('111.mp3', 'rb') as f:
rawfile = f.read()
for dirpath, dirnames, filenames in os.walk('E:/Exp/apic'):
for 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)
with open('111.mp3', 'wb') as f:
f.write(rawfile) #reset
代码显示我无法将整个图片嵌入到该 mp3 中,并且我的 mp3 播放器和手机都无法读取损坏的艺术品,那么问题到底是什么?虽然只有当我以前嵌入更大的图片时才能成功嵌入图片。
现在我将显示上述代码的结果:
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