我想從文件.m4a(類似于“.mp3”)中獲取音樂作品到 Tkinter 圖像中,以便在標簽上顯示。出于某種奇怪的原因,鏈接中的所有答案都使用: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 版本中發生了變化,eyeD3這eyed3是 Ubuntu 16.04.6 LTS 的另一個選項。我也在使用 Linux Kernel 4.14.188LTS,但我懷疑這是否重要。注意:我ffmpeg今天早上嘗試從 Python 調用將.m4a文件的插圖轉換為.jpg文件,但這很“復雜”,我希望eyed3或者eyeD3會更簡單。
1 回答

嚕嚕噠
TA貢獻1784條經驗 獲得超7個贊
使用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()
在我的電腦上運行良好。
添加回答
舉報
0/150
提交
取消