39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
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.")
|