Fix: extend clip if ends mid-vocal (no chorus cut-off), DejaVu Sans font (supports SLO/HR/BS chars), auto-upgrade to medium Whisper model for Slavic languages
This commit is contained in:
+35
-11
@@ -346,31 +346,46 @@ def smart_clip_range(chorus, transcript, video_duration,
|
||||
}
|
||||
|
||||
|
||||
def detect_audio_fade(clip_range, transcript):
|
||||
"""Določi fade-in/fade-out trajanje.
|
||||
def detect_audio_fade(clip_range, transcript, video_duration=None):
|
||||
"""Določi fade-in/fade-out trajanje + ev. razširi clip range, da fade
|
||||
ne reže besedila na koncu refrena.
|
||||
|
||||
Logika:
|
||||
- Če clip začne sredi vokala → 0.5s fade in
|
||||
- Če se konča sredi vokala → 1.0s fade out
|
||||
- Če se konča sredi vokala → razširi clip do konca segmenta (+ buffer),
|
||||
potem 1.0s fade out
|
||||
- Sicer manj fade
|
||||
"""
|
||||
cs, ce = clip_range["start"], clip_range["end"]
|
||||
|
||||
# Vokal pri začetku?
|
||||
# Najdi segment, ki konča znotraj clip-a (ali je clip end znotraj segmenta)
|
||||
starts_in_vocal = False
|
||||
ends_in_vocal = False
|
||||
end_segment = None
|
||||
for seg in transcript["segments"]:
|
||||
# Začetek clip-a znotraj segmenta
|
||||
if seg["start"] <= cs <= seg["end"]:
|
||||
starts_in_vocal = True
|
||||
# Konec clip-a znotraj segmenta
|
||||
if seg["start"] <= ce <= seg["end"]:
|
||||
ends_in_vocal = True
|
||||
end_segment = seg
|
||||
|
||||
fade_in = 0.5 if starts_in_vocal else 0.2
|
||||
fade_out = 1.5 if ends_in_vocal else 0.3
|
||||
# Če clip konča znotraj segmenta, razširi do konca segmenta + 0.5s buffer
|
||||
extended_end = ce
|
||||
if end_segment:
|
||||
extended_end = end_segment["end"] + 0.5
|
||||
if video_duration is not None:
|
||||
extended_end = min(extended_end, video_duration)
|
||||
|
||||
return {"fade_in": fade_in, "fade_out": fade_out}
|
||||
fade_in = 0.4 if starts_in_vocal else 0.2
|
||||
# Krajši fade out (0.5s) ker zdaj clip konča po koncu vokala
|
||||
fade_out = 0.5 if ends_in_vocal else 0.3
|
||||
|
||||
return {
|
||||
"fade_in": fade_in,
|
||||
"fade_out": fade_out,
|
||||
"extended_end": round(extended_end, 2),
|
||||
"ends_in_vocal": ends_in_vocal,
|
||||
}
|
||||
|
||||
|
||||
def analyze_with_claude(transcript, video_duration, target_duration=30):
|
||||
@@ -612,10 +627,19 @@ def main():
|
||||
f"(duration: {clip_range['duration']}s, source: {clip_range.get('source')})",
|
||||
file=sys.stderr)
|
||||
|
||||
# 7. Fade params
|
||||
fade = detect_audio_fade(clip_range, transcript)
|
||||
# 7. Fade params (lahko razširi clip end če konča sredi vokala)
|
||||
fade = detect_audio_fade(clip_range, transcript, video_duration=duration)
|
||||
print(f"🎚 Fade: in={fade['fade_in']}s, out={fade['fade_out']}s", file=sys.stderr)
|
||||
|
||||
# Če fade detection razširi end (ker clip konča sredi vokala), apply
|
||||
if fade.get("extended_end") and fade["extended_end"] > clip_range["end"]:
|
||||
old_end = clip_range["end"]
|
||||
new_end = min(fade["extended_end"], clip_range["start"] + args.max_duration)
|
||||
clip_range["end"] = round(new_end, 2)
|
||||
clip_range["duration"] = round(new_end - clip_range["start"], 2)
|
||||
print(f" ↳ Razširjen za {new_end - old_end:.1f}s (zaključek besedila)",
|
||||
file=sys.stderr)
|
||||
|
||||
result = {
|
||||
"video": str(video),
|
||||
"video_duration": duration,
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ ScaledBorderAndShadow: yes
|
||||
|
||||
[V4+ Styles]
|
||||
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
|
||||
Style: Default,Arial,56,{primary},&H00FFFFFF,&H00000000,&H00000000,1,0,0,0,100,100,0,0,1,5,1,2,80,80,400,1
|
||||
Style: Default,DejaVu Sans,56,{primary},&H00FFFFFF,&H00000000,&H00000000,1,0,0,0,100,100,0,0,1,5,1,2,80,80,400,1
|
||||
|
||||
[Events]
|
||||
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
||||
|
||||
Reference in New Issue
Block a user