Advertisement
Najeebsk

VIDEOS-MEREGE.pyw

Jun 30th, 2024
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog, messagebox
  3. import subprocess
  4. import os
  5.  
  6. class VideoMergerApp:
  7.     def __init__(self, root):
  8.         self.root = root
  9.         self.root.title("Najeeb Video Merger with FFMPEG")
  10.         self.root.geometry("340x160")
  11.         self.root.configure(bg="#4a4a4a")
  12.         self.video_files = []
  13.        
  14.        
  15.         self.label = tk.Label(root, text="Select video files to merge:")
  16.         self.label.pack(pady=10)
  17.        
  18.         self.select_button = tk.Button(root, text="Select Files", command=self.select_files)
  19.         self.select_button.pack(pady=5)
  20.        
  21.         self.merge_button = tk.Button(root, text="Merge Videos", command=self.merge_videos, state=tk.DISABLED)
  22.         self.merge_button.pack(pady=5)
  23.        
  24.         self.status_label = tk.Label(root, text="")
  25.         self.status_label.pack(pady=10)
  26.    
  27.     def select_files(self):
  28.         self.video_files = filedialog.askopenfilenames(title="Select Video Files", filetypes=[("Video Files", "*.mp4 *.mkv *.avi")])
  29.         if self.video_files:
  30.             self.status_label.config(text=f"{len(self.video_files)} files selected.")
  31.             self.merge_button.config(state=tk.NORMAL)
  32.         else:
  33.             self.status_label.config(text="No files selected.")
  34.             self.merge_button.config(state=tk.DISABLED)
  35.    
  36.     def merge_videos(self):
  37.         output_file = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
  38.         if not output_file:
  39.             return
  40.        
  41.         temp_file = "temp_list.txt"
  42.         with open(temp_file, "w") as f:
  43.             for file in self.video_files:
  44.                 f.write(f"file '{file}'\n")
  45.        
  46.         ffmpeg_command = f"ffmpeg -f concat -safe 0 -i {temp_file} -c copy {output_file}"
  47.         try:
  48.             subprocess.run(ffmpeg_command, check=True, shell=True)
  49.             self.status_label.config(text=f"Videos merged successfully into {output_file}")
  50.         except subprocess.CalledProcessError:
  51.             self.status_label.config(text="Error occurred while merging videos.")
  52.         finally:
  53.             os.remove(temp_file)
  54.             self.merge_button.config(state=tk.DISABLED)
  55.  
  56. if __name__ == "__main__":
  57.     root = tk.Tk()
  58.     app = VideoMergerApp(root)
  59.     root.mainloop()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement