You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
import os
|
|
import subprocess
|
|
import shutil
|
|
import tkinter as tk
|
|
from tkinter import filedialog, messagebox
|
|
|
|
def process_videos():
|
|
# GUI initialisieren und verstecken
|
|
root = tk.Tk()
|
|
root.withdraw()
|
|
root.attributes('-topmost', True)
|
|
|
|
# 1. Videos auswählen
|
|
video_paths = filedialog.askopenfilenames(
|
|
title="Wähle 9:16 Videos aus",
|
|
filetypes=[("Video files", "*.mp4 *.mov *.m4v")]
|
|
)
|
|
if not video_paths: return
|
|
|
|
# 2. Zielordner wählen
|
|
output_dir = filedialog.askdirectory(title="Wo sollen die Dateien gespeichert werden?")
|
|
if not output_dir: return
|
|
|
|
# Pfad zu FFmpeg (bitte prüfen mit 'which ffmpeg')
|
|
FFMPEG_PATH = '/opt/homebrew/bin/ffmpeg'
|
|
|
|
for path in video_paths:
|
|
filename = os.path.basename(path)
|
|
|
|
# A) ORIGINAL KOPIEREN
|
|
original_dest = os.path.join(output_dir, filename)
|
|
try:
|
|
shutil.copy2(path, original_dest)
|
|
except Exception as e:
|
|
print(f"Fehler beim Kopieren: {e}")
|
|
|
|
# B) 4:5 CROP ERSTELLEN
|
|
new_filename = filename.replace("9x16", "4x5")
|
|
|
|
if new_filename == filename:
|
|
name_part, ext_part = os.path.splitext(filename)
|
|
new_filename = f"{name_part}_4x5{ext_part}"
|
|
|
|
# Variable einheitlich benennen:
|
|
final_output_path = os.path.join(output_dir, new_filename)
|
|
|
|
# Center Crop 4:5 mit Hardware-Beschleunigung
|
|
crop_filter = "crop=iw:iw*1.25:0:(ih-out_h)/2"
|
|
|
|
try:
|
|
subprocess.run([
|
|
FFMPEG_PATH, '-i', path,
|
|
'-vf', crop_filter,
|
|
'-c:v', 'h264_videotoolbox', '-b:v', '10M',
|
|
'-c:a', 'copy', '-y',
|
|
final_output_path # Hier war der Fehler (out_4_5 existierte nicht)
|
|
], check=True)
|
|
except Exception as e:
|
|
print(f"Fehler beim Croppen von {filename}: {e}")
|
|
|
|
# 3. Finder öffnen und Abschlussmeldung
|
|
subprocess.run(['open', output_dir])
|
|
messagebox.showinfo("Erfolg", "Alle Videos wurden verarbeitet!")
|
|
|
|
if __name__ == "__main__":
|
|
# Unterdrückt die Tk-Warnung im Terminal
|
|
os.environ['TK_SILENCE_DEPRECATION'] = '1'
|
|
process_videos()
|