bachlorarbeit/cutClips.py
2025-06-16 12:29:08 +02:00

39 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from moviepy.video.io.VideoFileClip import VideoFileClip
from pathlib import Path
import sqlite3
# === Setup ===
input_video = Path("input/testVideoShort.mov")
output_dir = Path("output")
output_dir.mkdir(parents=True, exist_ok=True)
# === SQLite DB lesen ===
db_path = "clips_openai.db"
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Nur die Top 10 Clips mit höchstem score_total
cursor.execute("""
SELECT start, end, text
FROM highlights
ORDER BY score_total DESC
LIMIT 10
""")
highlights = cursor.fetchall()
# === Video laden ===
video = VideoFileClip(str(input_video))
# === Clips schneiden ===
for i, (start, end, text) in enumerate(highlights):
output_file = output_dir / f"highlight_{i+1}.mp4"
end = min(end, video.duration) # Sicherstellen, dass das Ende nicht über das Video hinausgeht
print(f"🎬 Exportiere Clip {i+1}: {start:.2f}s {end:.2f}s → {output_file.name}")
clip = video.subclipped(start, end)
clip.write_videofile(str(output_file), codec="libx264", audio_codec="aac")
# === Cleanup ===
conn.close()
video.close()
print("✅ Top 10 Clips exportiert.")