update system to use find Highlights *not tested
This commit is contained in:
1 parent
38e0cc6764
commit
7c96a5131b
8 files changed
+211
-86
No files matched your search
@@ -267,20 +267,48 @@ def format_timestamp(seconds):
|
||||
return f"{h:02d}:{m:02d}:{s:02d}" if h > 0 else f"{m:02d}:{s:02d}"
|
||||
|
||||
def highlights(video_path, keywords=None, top_n=5, clip_len=8, min_gap=12):
|
||||
if keywords is None:
|
||||
keywords = DEFAULT_KEYWORDS
|
||||
|
||||
av_score, duration = get_av_scores(video_path, sample_fps=0.5)
|
||||
|
||||
segments = load_text_from_srt(video_path.replace('.mp4', '.srt'))
|
||||
kw_score, kw_hits = score_keywords(segments, duration, keywords)
|
||||
|
||||
# FINAL SCORE: AV + keyword boost (keyword is huge if found)
|
||||
final_score = av_score + (kw_score * 1.5)
|
||||
final_score = (final_score - final_score.min()) / (final_score.max() - final_score.min() + 1e-6)
|
||||
final_score = np.convolve(final_score, np.ones(3)/3, mode='same')
|
||||
final_score = np.convolve(final_score, np.ones(3)/3, mode='same') # smooth
|
||||
|
||||
highlights = find_highlights(final_score, duration, top_n=top_n, clip_len=clip_len)
|
||||
|
||||
return highlights, kw_hits
|
||||
# --- OUTPUT ---
|
||||
print("\n" + "="*60)
|
||||
print("KEYWORD HITS:")
|
||||
for h in kw_hits:
|
||||
print(f" [{format_timestamp(h['timestamp'])}] ({h['keyword']}) -> {h['text']}")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("FINAL HIGHLIGHTS:")
|
||||
output_data = []
|
||||
for i, (start, end, score) in enumerate(highlights, 1):
|
||||
# find transcript in that window
|
||||
texts_in_window = [s['text'].strip() for s in segments if not (s['end'] < start or s['start'] > end)]
|
||||
transcript = " ".join(texts_in_window)[:120]
|
||||
|
||||
print(f"{i}. {format_timestamp(start)} - {format_timestamp(end)} (score {score:.2f}) | {transcript}")
|
||||
output_data.append({
|
||||
"id": i,
|
||||
"start_sec": float(start),
|
||||
"end_sec": float(end),
|
||||
"start_timestamp": format_timestamp(start),
|
||||
"end_timestamp": format_timestamp(end),
|
||||
"score": float(score),
|
||||
"transcript": transcript
|
||||
})
|
||||
|
||||
# Save timestamps to JSON
|
||||
with open("highlights.json", "w") as f:
|
||||
json.dump({"video": video_path, "keywords": keywords, "highlights": output_data, "keyword_hits": kw_hits}, f, indent=2)
|
||||
print(f"\nTimestamps saved to highlights.json")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Find highlights with Whisper keywords + timestamps")
|
||||
|
||||
Reference in new issue
Block a user