Skills › HyperFrames › media-use › transcriptCutFade.mjs
transcriptCutFade.mjs
21 lines · skills/media-use/scripts/lib/transcriptCutFade.mjs at a595755
1function round3(n) {
2 return Math.round(Number(n) * 1000) / 1000;
3}
5// 30ms in/out ramps kill the click at every concat boundary. A segment shorter
6// than 4x the ramp would spend its whole length fading, so scale down there and
7// skip entirely on a degenerate one. fadeIn/fadeOut are false at the export's
8// own true start/end, where there is no splice to smooth.
9export function fadeFilterFor(durationSeconds, { fadeIn, fadeOut }) {
10 if (!fadeIn && !fadeOut) return null;
11 const FADE_SECONDS = 0.03;
12 if (!Number.isFinite(durationSeconds) || durationSeconds <= 0.01) return null;
13 const d = Math.min(FADE_SECONDS, durationSeconds / 4);
14 const parts = [];
15 if (fadeIn) parts.push(`afade=t=in:st=0:d=${round3(d)}`);
16 if (fadeOut) {
17 const out = round3(durationSeconds - d);
18 if (out > 0) parts.push(`afade=t=out:st=${out}:d=${round3(d)}`);
19 }
20 return parts.length ? parts.join(",") : null;
21}