die anwendung crashed mit einer fehlermeldung nachdem eine zeit lang nach starten des…
- User
die anwendung crashed mit einer fehlermeldung nachdem eine zeit lang nach starten des prozesses gar nichts merkbares passiert. behebe alle fehler und sorge dafür das die anwendung die bearbeitung schnell und problemlos durchfpührt
import sys import os import threading import tkinter as tk from tkinter import filedialog, messagebox from tkinter import ttk from moviepy.video.io.VideoFileClip import VideoFileClip from moviepy.config import get_setting
class VideoSplitterApp: def init(self, root): self.root = root self.root.title('Video Splitter') self.root.geometry('500x400') self.input_file = '' self.output_folder = '' self.max_duration = 60 # Default maximum clip duration in seconds self.quality = 'Same as original' # Default quality
self.create_widgets() def create_widgets(self): # Input video selection input_frame = tk.Frame(self.root) input_frame.pack(pady=10, fill='x') self.input_label = tk.Label(input_frame, text='No video selected') self.input_label.pack(side='left', padx=5) self.select_input_button = tk.Button(input_frame, text='Select Video', command=self.select_input_video) self.select_input_button.pack(side='right', padx=5) # Maximum clip duration duration_frame = tk.Frame(self.root) duration_frame.pack(pady=10, fill='x') duration_label = tk.Label(duration_frame, text='Max clip duration (seconds):') duration_label.pack(side='left', padx=5) self.duration_spinbox = tk.Spinbox(duration_frame, from_=1, to=3600, width=5) self.duration_spinbox.delete(0, 'end') self.duration_spinbox.insert(0, '60') self.duration_spinbox.pack(side='right', padx=5) # Output folder selection output_frame = tk.Frame(self.root) output_frame.pack(pady=10, fill='x') self.output_label = tk.Label(output_frame, text='Output folder not selected') self.output_label.pack(side='left', padx=5) self.select_output_button = tk.Button(output_frame, text='Select Output Folder', command=self.select_output_folder) self.select_output_button.pack(side='right', padx=5) # Quality selection quality_frame = tk.Frame(self.root) quality_frame.pack(pady=10, fill='x') quality_label = tk.Label(quality_frame, text='Output Quality:') quality_label.pack(side='left', padx=5) self.quality_combo = ttk.Combobox(quality_frame, values=['Same as original', 'Low', 'Medium', 'High'], state='readonly') self.quality_combo.current(0) # Set default to 'Same as original' self.quality_combo.pack(side='right', padx=5) # Progress bar progress_frame = tk.Frame(self.root) progress_frame.pack(pady=10, fill='x') self.progress_var = tk.DoubleVar() self.progress_bar = ttk.Progressbar(progress_frame, variable=self.progress_var, maximum=100) self.progress_bar.pack(fill='x', padx=5) # Start button start_frame = tk.Frame(self.root) start_frame.pack(pady=20) self.start_button = tk.Button(start_frame, text='Start', command=self.start_splitting) self.start_button.pack() def select_input_video(self): filetypes = [('Video files', '*.mp4;*.avi;*.mov;*.mkv')] file_name = filedialog.askopenfilename(title='Select Video File', filetypes=filetypes) if file_name: self.input_file = file_name self.input_label.config(text=f"Selected: {os.path.basename(file_name)}") # Set default output folder to input video's folder self.output_folder = os.path.dirname(file_name) self.output_label.config(text=f"Output Folder: {self.output_folder}") def select_output_folder(self): folder = filedialog.askdirectory(title='Select Output Folder') if folder: self.output_folder = folder self.output_label.config(text=f"Output Folder: {self.output_folder}") def start_splitting(self): if not self.input_file: messagebox.showwarning("No Video Selected", "Please select a video file to split.") return if not self.output_folder: messagebox.showwarning("No Output Folder", "Please select an output folder.") return try: self.max_duration = int(self.duration_spinbox.get()) except ValueError: messagebox.showerror("Invalid Duration", "Please enter a valid maximum clip duration.") return self.quality = self.quality_combo.get() # Disable the start button to prevent multiple clicks self.start_button.config(state='disabled') self.progress_var.set(0) self.progress_bar.update() # Use threading to prevent GUI freezing threading.Thread(target=self.split_video).start() def split_video(self): try: video = VideoFileClip(self.input_file) duration = video.duration max_duration = self.max_duration base_name = os.path.splitext(os.path.basename(self.input_file))[0] extension = os.path.splitext(self.input_file)[1] quality_settings = { 'Same as original': {}, 'Low': {'preset': 'ultrafast', 'bitrate': '500k'}, 'Medium': {'preset': 'medium', 'bitrate': '1000k'}, 'High': {'preset': 'slow', 'bitrate': '2000k'} } # Calculate number of clips num_clips = int(duration // max_duration) + int(duration % max_duration > 0) for i in range(num_clips): start_time = i * max_duration end_time = min(start_time + max_duration, duration) clip = video.subclip(start_time, end_time) output_file = f"{base_name}_part{i+1}{extension}" output_path = os.path.join(self.output_folder, output_file) # Set quality parameters write_kwargs = {} if self.quality != 'Same as original': write_kwargs = quality_settings[self.quality] clip.write_videofile( output_path, codec='libx264', audio_codec='aac', **write_kwargs, threads=4, # Utilize 4 threads for faster processing temp_audiofile=os.path.join(self.output_folder, f"temp_audio_{i}.m4a"), remove_temp=True, logger=None # Disable verbose output ) clip.close() self.update_progress((i + 1) / num_clips * 100) video.close() self.update_progress(100) messagebox.showinfo("Success", "Video splitting completed successfully.") except Exception as e: messagebox.showerror("Error", f"An error occurred: {e}") finally: self.start_button.config(state='normal') def update_progress(self, value): self.progress_var.set(value) self.progress_bar.update() - Assistant