86 lines
2.8 KiB
Python
86 lines
2.8 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
import glob
|
|
|
|
SNAPSHOT_PATH = r'C:\Users\Jannik\AppData\Roaming\FilmCraft\Recovery\1794074002-20864\snapshot.fcproj'
|
|
AUTOSAVE_DIR = r'C:\Users\Jannik\AppData\Roaming\FilmCraft\Auto-Save'
|
|
OUTPUT_DIR = r'C:\GitHub\VocoLoom\raw_snippets'
|
|
VIDEO_PATH = r'C:\GitHub\MDR Bilderbogen - Die Welt ist unser Feld vom 22.10.1995.mp4'
|
|
TICKS_PER_SEC = 254016000000
|
|
|
|
def get_latest_project_file():
|
|
candidates = []
|
|
if os.path.exists(SNAPSHOT_PATH):
|
|
candidates.append((os.path.getmtime(SNAPSHOT_PATH), SNAPSHOT_PATH))
|
|
for f in glob.glob(os.path.join(AUTOSAVE_DIR, '*.fcproj')):
|
|
candidates.append((os.path.getmtime(f), f))
|
|
if not candidates:
|
|
raise FileNotFoundError("Keine FilmCraft-Projektdatei gefunden.")
|
|
candidates.sort(reverse=True)
|
|
return candidates[0][1]
|
|
|
|
def sec_to_timecode(sec, fps=25):
|
|
frames = int(round((sec - int(sec)) * fps))
|
|
m, s = divmod(int(sec), 60)
|
|
h, m = divmod(m, 60)
|
|
return f"{h:02d}-{m:02d}-{s:02d}-{frames:02d}"
|
|
|
|
def extract_all():
|
|
proj_file = get_latest_project_file()
|
|
print(f"Lese Projektdatei: {proj_file}")
|
|
with open(proj_file, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
seq = None
|
|
for item in data['project']['items'].values():
|
|
if 'Sequence' in item.get('kind', {}):
|
|
seq = item['kind']['Sequence']
|
|
break
|
|
|
|
if not seq:
|
|
print("Keine Sequenz im Projekt gefunden.")
|
|
return
|
|
|
|
markers = sorted(seq.get('markers', []), key=lambda m: m['start'])
|
|
print(f"{len(markers)} Marker gefunden ({len(markers)//2} Paare).")
|
|
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
total_dur = 0.0
|
|
|
|
for i in range(0, len(markers) - 1, 2):
|
|
m_start = markers[i]
|
|
m_end = markers[i+1]
|
|
|
|
t_start = m_start['start'] / TICKS_PER_SEC
|
|
t_end = m_end['start'] / TICKS_PER_SEC
|
|
dur = t_end - t_start
|
|
total_dur += dur
|
|
|
|
tc_start = sec_to_timecode(t_start)
|
|
tc_end = sec_to_timecode(t_end)
|
|
|
|
out_name = f"snippet_{i//2 + 1:02d}_{tc_start}_to_{tc_end}.wav"
|
|
out_path = os.path.join(OUTPUT_DIR, out_name)
|
|
|
|
cmd = [
|
|
'ffmpeg', '-y',
|
|
'-ss', f"{t_start:.4f}",
|
|
'-to', f"{t_end:.4f}",
|
|
'-i', VIDEO_PATH,
|
|
'-vn',
|
|
'-c:a', 'pcm_s16le',
|
|
'-ar', '44100',
|
|
out_path
|
|
]
|
|
res = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
if res.returncode == 0:
|
|
print(f" [OK] Snippet {i//2 + 1:02d}: {tc_start} -> {tc_end} ({dur:.2f}s) -> {out_name}")
|
|
else:
|
|
print(f" [FEHLER] Snippet {i//2 + 1:02d} fehlgeschlagen.")
|
|
|
|
print(f"\nGesamtdauer extrahiert: {total_dur:.2f} Sekunden ({total_dur/60:.2f} Minuten)")
|
|
|
|
if __name__ == '__main__':
|
|
extract_all()
|