使用 Mutagen 在 MP4 文件中嵌入专辑封面
Embedding album cover in MP4 file using Mutagen
我希望能够使用诱变剂将专辑封面添加到文件中,但是当我将其添加为文件时,它 returns 具有:
File "D:\Download\pandora\renamingMETAEFF.pyw", line 71, in <module>
meta['covr'] = image
File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\_file.py", line 67, in __setitem__
self.tags[key] = value
File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 357, in __setitem__
self._render(key, value)
File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 371, in _render
return render_func(self, key, value)
File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 732, in __render_cover
b"data", struct.pack(">2I", imageformat, 0) + cover))
TypeError: can't concat bytes to str
相关代码是这样的:
from mutagen.mp4 import MP4
image = jpgname + '.jpg'
meta['\xa9nam'] = song
meta['\xa9ART'] = artist
meta['\xa9alb'] = album
meta = MP4(songPath)
meta['covr'] = image
meta.save()
其余的元数据工作得很好,但是图像部分完全破坏了整个代码。
来自mutagen docs:
MP4 meta 'covr' – cover artwork, list of MP4Cover objects (which are tagged strs).
MP4Cover imageformat – format of the image (either FORMAT_JPEG or FORMAT_PNG)
from mutagen.mp4 import MP4, MP4Cover
video = MP4("test.mp4")
video["\xa9nam"] = "Test1"
video["\xa9ART"] = "Test2"
video["\xa9alb"] = "Test3"
with open("cover.jpg", "rb") as f:
video["covr"] = [
MP4Cover(f.read(), imageformat=MP4Cover.FORMAT_JPEG)
]
video.save()
我希望能够使用诱变剂将专辑封面添加到文件中,但是当我将其添加为文件时,它 returns 具有:
File "D:\Download\pandora\renamingMETAEFF.pyw", line 71, in <module> meta['covr'] = image File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\_file.py", line 67, in __setitem__ self.tags[key] = value File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 357, in __setitem__ self._render(key, value) File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 371, in _render return render_func(self, key, value) File "C:\Users\AMD\AppData\Local\Programs\Python\Python35\lib\site-packages\mutagen\mp4\__init__.py", line 732, in __render_cover b"data", struct.pack(">2I", imageformat, 0) + cover)) TypeError: can't concat bytes to str
相关代码是这样的:
from mutagen.mp4 import MP4
image = jpgname + '.jpg'
meta['\xa9nam'] = song
meta['\xa9ART'] = artist
meta['\xa9alb'] = album
meta = MP4(songPath)
meta['covr'] = image
meta.save()
其余的元数据工作得很好,但是图像部分完全破坏了整个代码。
来自mutagen docs:
MP4 meta 'covr' – cover artwork, list of MP4Cover objects (which are tagged strs).
MP4Cover imageformat – format of the image (either FORMAT_JPEG or FORMAT_PNG)
from mutagen.mp4 import MP4, MP4Cover
video = MP4("test.mp4")
video["\xa9nam"] = "Test1"
video["\xa9ART"] = "Test2"
video["\xa9alb"] = "Test3"
with open("cover.jpg", "rb") as f:
video["covr"] = [
MP4Cover(f.read(), imageformat=MP4Cover.FORMAT_JPEG)
]
video.save()