diff --git a/ffmpeg_utils.py b/ffmpeg_utils.py index 4ab6ea0..26621b0 100644 --- a/ffmpeg_utils.py +++ b/ffmpeg_utils.py @@ -63,11 +63,25 @@ METADATA_SCRUB = ["-map_metadata", "-1", "-map_chapters", "-1", # which means the quiet ones just sound thin next to everything else in the # feed — the loud ones aren't rewarded, the quiet ones are punished. # -# I=-14 matches the platforms' target, TP=-1.5 leaves headroom so their own -# re-encode can't clip, LRA=11 is the usual allowance for speech. Applied at -# the clip cut, where the audio is being encoded to AAC anyway, so it costs -# nothing extra. AUDIO_NORMALIZE=0 turns it off. -LOUDNORM_FILTER = "loudnorm=I=-14:TP=-1.5:LRA=11" +# I=-14 matches the platforms' target, LRA=11 is the usual allowance for speech. +# Applied at the clip cut, where the audio is being encoded to AAC anyway, so it +# costs nothing extra. AUDIO_NORMALIZE=0 turns it off. +# +# TP=-2.0, not the -1.5 that matches the platforms' own advice, because the +# ceiling is enforced BEFORE the AAC encode and the encoder then adds +# inter-sample peaks on top. Measured over 14 corpus clips (31-jul-2026): +# +# TP=-1.5 peak reached +0.2 dBTP, 1 clip clipping, 8 above -1.0 +# TP=-2.0 peak reached -0.3 dBTP, 0 clipping, 5 above -1.0 +# TP=-3.0 peak reached -0.9 dBTP, 0 clipping, 1 above -1.0 +# +# -3.0 also costs level: only 8 of 14 stayed inside -15..-13 LUFS versus 12 at +# -2.0, and level is what the listener notices. Two other fixes were tried and +# do NOT work, so don't reach for them again: an `alimiter` after loudnorm +# (limits sample peaks, not inter-sample, and measured WORSE at +0.7), and +# two-pass loudnorm with linear=true (+0.4, still clipping). The overshoot is +# the codec's, so the only lever is headroom. +LOUDNORM_FILTER = "loudnorm=I=-14:TP=-2.0:LRA=11" def audio_encode_args(): diff --git a/punch_in.py b/punch_in.py index bae27ed..320fcb0 100644 --- a/punch_in.py +++ b/punch_in.py @@ -36,14 +36,28 @@ FALL_SECONDS = 0.55 # Never punch twice inside this window. Two pushes in quick succession read as a # glitch, and the second one lands before the first has released. -MIN_GAP_SECONDS = 4.0 - +# # Audio-envelope resolution used to find beats. BEAT_WINDOW = 0.2 # A beat must exceed the clip's median loudness by this much of the gap to its # peak. Low values punch on every syllable; this keeps it to real emphasis. -BEAT_PROMINENCE = 0.45 +# +# These two were shipped at 4.0/0.45 and that produced 8.4 punches per minute of +# clip, one every seven seconds. That is not a push on the beat, it is a twitch. +# Swept over 20 corpus clips (31-jul-2026), punches per minute, median and max: +# +# gap prom median max gap prom median max +# 4.0 0.45 8.4 11.8 12.0 0.60 2.9 4.6 +# 4.0 0.75 2.4 5.8 18.0 0.45 2.9 3.9 +# 8.0 0.60 3.4 5.9 18.0 0.60 2.8 3.0 +# +# 18.0/0.60 is picked for having the tightest spread, not just the right median: +# a setting whose worst case is 3.0/min never surprises anyone, while 12.0/0.60 +# has the same median but can still reach 4.6 on a loud clip. No setting left a +# clip with zero punches. +MIN_GAP_SECONDS = 18.0 +BEAT_PROMINENCE = 0.60 def _ease(t):