最近想写一个压缩视频的小程序,没打包前运行没问题,但是用pyinstaller打包后就报错,源码如下,求大神指点。
报错信息如图。
[Python] 纯文本查看 复制代码 import tkinter as tkfrom tkinter import filedialog, messagebox
from moviepy.video.io.VideoFileClip import VideoFileClip
class VideoCompressorApp:
def __init__(self, root):
self.root = root
self.root.title("视频压缩器")
# 创建选择视频按钮
self.select_button = tk.Button(root, text="选择视频文件", command=self.select_file)
self.select_button.pack(pady=20)
# 创建压缩按钮
self.compress_button = tk.Button(root, text="压缩视频", command=self.compress_video, state=tk.DISABLED)
self.compress_button.pack(pady=20)
# 显示选择的文件路径
self.file_path_label = tk.Label(root, text="")
self.file_path_label.pack(pady=10)
self.video_path = ""
def select_file(self):
self.video_path = filedialog.askopenfilename(filetypes=[("视频文件", "*.mp4 *.avi *.mov")])
if self.video_path:
self.file_path_label.config(text=self.video_path)
self.compress_button.config(state=tk.NORMAL)
def compress_video(self):
if not self.video_path:
messagebox.showerror("错误", "请先选择一个视频文件")
return
output_path = self.video_path.rsplit('.', 1)[0] + "_compressed.mp4"
try:
with VideoFileClip(self.video_path) as video:
video.write_videofile(output_path, bitrate="500k") # 设定压缩比特率
messagebox.showinfo("成功", f"视频已压缩并保存为:\n{output_path}")
except Exception as e:
messagebox.showerror("错误", f"压缩视频时出错:{str(e)}")
if __name__ == "__main__":
root = tk.Tk()
app = VideoCompressorApp(root)
root.mainloop()
|