// How a cut crossfades from one clip into the next (`render.transitionStyle`): // one of ffmpeg xfade's own transition names. Absent = "fade", the dissolve // every cut has always had. "fadeblack" dips through black, so a jump in time // reads as a jump when two clips share a layout (a stream's webcam frame). // The length is still `render.transition`; a THEN/NOW wipe, a whip and a // teaser's dip keep their own look. // "blurslide" is not an xfade name: a quick, eased push. The outgoing clip // nudges right by `render.slide.travel` of the width while the next settles in // from the left (cubic ease-out: it moves fast and lands softly), the two // crossfading under a smoothstep; the frame edge a push uncovers is MIRRORED, // not clamped (a clamped read repeats the edge column into a streaked strip). // The smear along the motion is ffmpeg's directional blur (`dblur`) on each // clip's seam frames, in bands whose radius follows the push's speed (most at // the start, none as it lands), and those frames take a light temporal grain. // // The expression is closed-form -- no st()/ld(). xfade evaluates a custom // expression on slice threads that share ONE expression's registers, so a // stored value is another row's by the time it is read: measured, white into // white came out with tens of thousands of black pixels on two of five seam // frames (2026-10-21, ffmpeg 9.0.2). The smear used to be nine taps spaced // by the push's speed in the same expression; at any real travel the taps // sat many pixels apart and drew stepped copies of text instead of a blur. // // The style list, the slide's knobs and their checks are the look's rules // (common lib/report/look.mjs, release 38): re-exported here, so the writer, // the build and the video assistant refuse the same things. import { slideOf, transitionStyleOf } from "yt-dlp-transcript-common/lib/report/look.mjs"; export { SLIDE_BOUNDS, SLIDE_DEFAULTS, TRANSITION_STYLES, slideOf, transitionStyleOf, validateSlide, validateTransitionStyle, } from "yt-dlp-transcript-common/lib/report/look.mjs"; /** * The push as an xfade custom expression. P runs 1 -> 0 over the join, so the * ease-out's progress 1-(1-p)^3 is 1-P^3: the outgoing picture is read * travel*W*(1-P^3) to the left, the incoming travel*W*P^3 to the right, each * mirrored at the frame edge, mixed by a smoothstep over p in [0.1, 0.7]. * a0/a1/a2 and b0/b1/b2 read the two inputs' planes (each plane's own W), so * it works on any planar format. `D` is unused (the smear is `blurSlideEdges`) * and kept for the callers' signature. */ export function pushExpr(render, _D) { const { travel } = slideOf(render); const pl = (c, x) => `if(eq(PLANE,0),${c}0(${x},Y),if(eq(PLANE,1),${c}1(${x},Y),${c}2(${x},Y)))`; const A = pl("a", `abs(X-${travel}*W*(1-P*P*P))`); const B = pl("b", `W-1-abs(W-1-X-${travel}*W*P*P*P)`); const m = "clip((0.9-P)/0.6,0,1)"; return `${A}+(${B}-${A})*${m}*${m}*(3-2*${m})`; } /** The xfade transition for a plain join `D` seconds long. */ export const xfadeTransitionOf = (render, D = render?.transition ?? 0.5) => transitionStyleOf(render) === "blurslide" ? `custom:expr='${pushExpr(render, D)}'` : transitionStyleOf(render); /** The smear's bands across a join: each a quarter of it, blurred at its middle's speed. */ const SMEAR_BANDS = 4; /** * The seam filters a blur slide puts on one input `d` seconds long, joined * over `D` seconds: the smear (`dblur` trailing the motion, in SMEAR_BANDS * bands sized from the push's speed at each band's middle, a band under half * a pixel left out) over the join's whole length, * and the grain on the half-join nearest the seam -- on its tail when a plain * join follows it, on its head when one precedes it. "" when the style is not * "blurslide", `D` is 0, smear and grain are both 0, or neither edge is a * plain join (a dip, a wipe and a whip keep their own look). */ export function blurSlideEdges(d, D, render, { tail = false, head = false } = {}) { const { grain, blur, travel } = slideOf(render); if (transitionStyleOf(render) !== "blurslide" || !(D > 0) || (!tail && !head)) return ""; const out = []; const frames = Math.max(1, D * (render?.fps ?? 30)); const W = render?.width ?? 1920; const f3 = (n) => n.toFixed(3); if (blur > 0 && travel > 0) { for (let k = 0; k < SMEAR_BANDS; k += 1) { const p = (k + 0.5) / SMEAR_BANDS; // Both pictures move right at 3*travel*W*(1-p)^2/frames px per frame // (1-P^3 and P^3 alike). dblur is one-sided -- an exponential tail on // the `angle` side about 2*radius long (measured on a 1-px line) -- so // angle 180 trails each picture's motion, and blur 1 (a frame's travel) // is a radius of half the speed. const r = (blur * 3 * travel * W * (1 - p) ** 2) / frames / 2; if (r < 0.5) continue; const [p0, p1] = [k / SMEAR_BANDS, (k + 1) / SMEAR_BANDS]; const win = []; if (tail) win.push(`between(t,${f3(d - D + p0 * D)},${f3(d - D + p1 * D)})`); if (head) win.push(`between(t,${f3(p0 * D)},${f3(p1 * D)})`); out.push(`dblur=angle=180:radius=${r.toFixed(1)}:enable='${win.join("+")}'`); } } if (grain > 0) { const w = D / 2; const parts = []; if (tail) parts.push(`gte(t,${f3(d - w)})`); if (head) parts.push(`lt(t,${f3(w)})`); out.push(`noise=alls=${Math.round(grain)}:allf=t+u:enable='${parts.join("+")}'`); } return out.join(","); }