video / src /jiangnan /engine /timeline.ts
Surf
暮归江南 · v3 步骤2:黑屏修复——WebGL 上下文丢失恢复、逐帧校验与重渲染、最低可用 H.264 Level、后台节流规避、缩短片头黑场;附验证脚本
44d2dac
Raw History Blame Contribute Delete
4.07 kB
// Film timeline: shots, sun path, lighting cues and narration.
import { clamp, lerp, smoothstep } from './rng'
export const DURATION = 86
export interface ShotInfo { id: number; name: string; t0: number; t1: number }
export const SHOTS: ShotInfo[] = [
{ id: 1, name: '山谷航拍', t0: 0, t1: 9 },
{ id: 2, name: '贴水滑行', t0: 9, t1: 17 },
{ id: 3, name: '石拱桥', t0: 17, t1: 25 },
{ id: 4, name: '老水车', t0: 25, t1: 32 },
{ id: 5, name: '石板街集市', t0: 32, t1: 40 },
{ id: 6, name: '村口古樟', t0: 40, t1: 48 },
{ id: 7, name: '梯田竹林', t0: 48, t1: 55 },
{ id: 8, name: '灯笼次第', t0: 55, t1: 65 },
{ id: 9, name: '夜河灯影', t0: 65, t1: 74 },
{ id: 10, name: '星夜全景', t0: 74, t1: DURATION },
]
export function shotAt(t: number) {
for (const s of SHOTS) if (t < s.t1) return s
return SHOTS[SHOTS.length - 1]
}
// sun elevation in degrees
const SUN_KEYS: [number, number][] = [
[0, 8.5], [17, 6.6], [32, 4.6], [44, 2.6], [52, 0.9], [57, -0.8], [62, -2.8], [68, -5.2], [76, -7.6], [DURATION, -9.8],
]
function keyed(keys: [number, number][], t: number) {
if (t <= keys[0][0]) return keys[0][1]
for (let i = 1; i < keys.length; i++) {
if (t <= keys[i][0]) {
const f = (t - keys[i - 1][0]) / (keys[i][0] - keys[i - 1][0])
const s = f * f * (3 - 2 * f)
return lerp(keys[i - 1][1], keys[i][1], lerp(f, s, 0.5))
}
}
return keys[keys.length - 1][1]
}
export function sunElevation(t: number) {
return keyed(SUN_KEYS, t)
}
/** Sun azimuth: angle in XZ plane measured from +x toward +z. Sets toward west-south-west. */
export function sunAzimuth(t: number) {
return Math.PI + 0.2 + t * 0.0009
}
export function nightFactor(t: number) {
return smoothstep(-1.5, -8.5, sunElevation(t))
}
// lantern & window lighting
export const LANTERN_START = 58.4
export const LANTERN_SPAN = 7
export const WINDOW_START = 58.5
export const WINDOW_SPAN = 12
export interface Cue { id: string; t: number; text: string; dur: number }
// dur is the measured length of the generated narration audio (seconds)
export const NARRATION: Cue[] = [
{ id: 'n01', t: 1.6, text: '江南的黄昏,总是来得很慢。', dur: 3.31 },
{ id: 'n02', t: 9.8, text: '一条小河,把整座村子轻轻揽在怀里。', dur: 4.61 },
{ id: 'n03', t: 17.8, text: '石桥弯成半个月亮,水里,再补上另外半个。', dur: 4.92 },
{ id: 'n04', t: 25.6, text: '老水车吱呀吱呀地转,把一天的光阴,一勺一勺舀回河里。', dur: 5.95 },
{ id: 'n05', t: 33.0, text: '集市还没散。竹篮、陶罐、檐下的腊肉,都染上了夕阳的颜色。', dur: 7.2 },
{ id: 'n06', t: 40.8, text: '村口的老樟树站了几百年,看着人们挑着担子出去,又挑着担子回来。', dur: 7.08 },
{ id: 'n07', t: 48.6, text: '远山的梯田一层层暗下去,白鹭,也该回竹林了。', dur: 5.4 },
{ id: 'n08', t: 56.0, text: '炊烟升起来的时候,第一盏灯笼亮了。一盏,接着一盏。', dur: 6.22 },
{ id: 'n09', t: 66.0, text: '灯火落进河里,整条河,都暖了。', dur: 4.1 },
{ id: 'n10', t: 75.0, text: '星星出来了。水乡睡在一层薄薄的雾里。这里,是家的方向。', dur: 7.13 },
]
export function cueAt(t: number) {
for (const c of NARRATION) if (t >= c.t - 0.15 && t < c.t + c.dur + 0.5) return c
return null
}
export const TITLE = '暮归江南'
export const SUBTITLE = '一座水乡村庄的日落与灯火'
/** Title card opacity over time (opening + ending). */
export function titleAlpha(t: number) {
const a = smoothstep(2.6, 4.2, t) * (1 - smoothstep(7.4, 8.8, t))
return clamp(a)
}
export function endAlpha(t: number) {
return smoothstep(DURATION - 6.2, DURATION - 4.4, t)
}
export function fadeBlack(t: number) {
// fade in from black at start, fade out at the end
// (v3: the opening fade is 0.9 s instead of 1.6 s so the first second is not a black screen)
return Math.max(1 - smoothstep(0, 0.9, t), smoothstep(DURATION - 1.2, DURATION, t))
}