// THE COLOUR RANGE of an encode (operator, 5 Nov: "the background brightens // basically exactly at the 37m mark during the transition"). ffmpeg 7.1+ // negotiates the output's range across the whole filter graph: one JPEG input // (an attachment, a picture, an avatar) makes a post item's segment FULL range // (`yuvj420p`, pc), though its cards are PNGs and `-pix_fmt yuv420p` is asked. // Every other segment is limited (tv, or untagged, which players read as tv), // and the master is those segments end to end: a player reads one range for // the whole file, so the page's #12100c is Y=16 in one item and Y=30 in the // next -- the stage jumps a shade at the cut. Pinning `-color_range tv` makes // ffmpeg convert (not just tag), so every segment's page decodes to the same // colour. The pin rides AFTER the encode args, never in them: it is not a key // term (a limited-range segment comes out byte-identical), and a cached // segment that came out full range is rebuilt by its probe (isFullRange). // // Plain node; the probe's runner is a parameter. /** The output options that pin an encode to limited (tv) range, converting. */ export const LIMITED_RANGE = Object.freeze(["-color_range", "tv"]); /** * Is `file`'s video stream FULL range (`pc`, e.g. `yuvj420p`)? `exec`: * execFile-promise style (`{ stdout }`). False when the probe fails or says * anything else -- a probe never breaks a build, it only asks for a rebuild. */ export async function isFullRange(file, { exec, ffprobe = "ffprobe" }) { try { const r = await exec(ffprobe, ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=color_range,pix_fmt", "-of", "json", file]); const s = JSON.parse(String(r?.stdout ?? "{}"))?.streams?.[0]; return !!s && (s.color_range === "pc" || /^yuvj/.test(String(s.pix_fmt ?? ""))); } catch { return false; } }