【问题标题】:There is an errors embed album art with mutagen?使用诱变剂嵌入专辑封面时出错?
【发布时间】:2013-08-09 12:00:28
【问题描述】:

问题是,每当我将图片嵌入到 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

【问题讨论】:

    标签: python mp3 id3 mutagen


    【解决方案1】:

    尝试改变:

    mime = 'image/jpg' to 'image/jpeg'
    

    我之前也遇到过类似的问题,这对我有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 2012-11-19
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多