0

类似于这个问题:

我想将.m4a文件(类似于“.mp3”)中的音乐作品放入 Tkinter Image 中,以便在标签上显示。

出于某种奇怪的原因,链接中的所有答案都使用:

import eyed3

但我必须使用

import eyeD3

安装我必须使用:

sudo apt install python-eyed3
sudo apt install eyed3

我最迟在 2021 年之前运行 Ubuntu 16.04.6 LTS,这意味着我使用的是 Python 2.7.12。我了解语法和命名约定可能在 Python 3.5 版本中发生了变化,eyeD3eyed3是 Ubuntu 16.04.6 LTS 的另一个选项。我也在使用 Linux Kernel 4.14.188LTS,但我怀疑这很重要。

注意:ffmpeg今天早上尝试从 Python 调用将.m4a文件的艺术作品转换为.jpg文件,但这很“复杂”,我希望eyed3或者eyeD3会更简单。

4

1 回答 1

3

使用file.tag.images并迭代它,用于i.image_data获取图像的字节数。

例如:

import eyed3, io
from PIL import Image, ImageTk
import tkinter as tk

root = tk.Tk()
file = eyed3.load(r"music_path")

# if there contains many images
for i in file.tag.images: 
     img = ImageTk.PhotoImage(Image.open(io.BytesIO(i.image_data)))
     tk.Label(root, image=img).pack()

# or if there only one image here:

# img = ImageTk.PhotoImage(Image.open(io.BytesIO(file.tag.images[0].image_data)))
# tk.Label(root, image=img).pack()

root.mainloop()

在我的电脑上运行良好。 在此处输入图像描述

于 2020-07-29T03:19:48.193 回答