code wiki / (root) / nx_ts_marks.nx

nx_ts_marks.nx

buildroot/runtime/nx_ts_marks.nx

16610 B374 linesdepth 2pulls 2 transitivereach 6 importersview sourcekind librarytopic ts
docsdependenciesstructsconstsfunctions

about

nx_ts_marks.nx -- sovereign CLIP-ANALYSIS markers for a media asset (the first "clip analysis" payload the operator asked for: DEAD-AIR/silence, extensible to scene/black-frame/behavior). Pure + gate-able. DEAD-AIR by DEMUX signal (works on ARBITRARY streaming content -- no decode, which is limited to our own baseline test bitstreams): silence makes an audio encoder emit far fewer bytes. We bin audio payload bytes into fixed time windows during the single TS scan, then a bin is "silent" if it holds < FRAC of the asset's OWN median/mean bin (bitrate-AGNOSTIC by construction -- a 96k and a 320k stream both self-calibrate). Runs of silent bins >= MIN_DEADAIR_MS become dead-air markers. The threshold is RELATIVE, so no magic byte count. NXMK sidecar section (appended AFTER the NXVI keyframe table; v2 readers read only up to nkf keyframes and IGNORE this tail -> BACK-COMPAT, no format-version bump, no gallery seek regression). Marker type: 1=dead-air. "NXMK"(4) nmarks(8) then nmarks * { type(4) start_ms(8) end_ms(8) score(4) }. license_tier: ORIGINAL

dependencies 1 imports · 5 importers

nx_syscalls.nx nx_ts_marks.nx nx_coach_markers.nx nx_gallery_serve.nx nx_ts_index.nx nx_ts_marks_gate.nx nx_vidclass_adversary_gate.nx

imports: nx_syscalls.nx

imported by: nx_coach_markers.nxnx_gallery_serve.nxnx_ts_index.nxnx_ts_marks_gate.nxnx_vidclass_adversary_gate.nx

structs

none

consts

14const TM_MAGIC_60000: i64 = 60000
17const TM_BIN_MS: i64 = 500 // audio-byte accumulation window
18const TM_SIL_NUM: i64 = 15 // silent if bin < median * 15/100 (15% of typical loudness)
19const TM_SIL_DEN: i64 = 100
20const TM_MIN_DEADAIR_MS: i64 = 1500 // a run must span >= this to count as dead air (not a normal pause)
21const TM_MOTION_NUM: i64 = 160 // high-motion if a video-byte window > 160% of the median window (P-frame bitrate = motion)
22const TM_MOTION_DEN: i64 = 100
23const TM_MIN_MOTION_MS: i64 = 1500 // a high-motion run must span >= this (sustained activity, not a single spike)
24const TM_SCENE_NUM: i64 = 200 // scene-cut if a window > 200% of the PREVIOUS window (prediction reset at a cut)
25const TM_SCENE_DEN: i64 = 100
26const TM_RHYTHM_NUM: i64 = 60 // rhythmic if the best autocorrelation peak >= 60% of lag-0 energy (strong periodicity)
27const TM_RHYTHM_DEN: i64 = 100
28const TM_MIN_RHYTHM_MS: i64 = 4000
29const TM_STATIC_PCT: i64 = 25 // nothing-happening threshold = this percentile of the file OWN video-byte distribution. Self-calibrating: the measured corpus caps peaks but lets bitrate COLLAPSE when the scene is static (real minima 8-33 percent of median).
30const TM_MIN_STATIC_MS: i64 = 3000 // a static run must span >= this to be worth cutting; shorter is a normal pause
31const TM_STATIC_GUARD_NUM: i64 = 70 // if p25 >= 70 percent of median the stream has NO downward range -- REFUSE rather than mark the whole file dead
32const TM_STATIC_GUARD_DEN: i64 = 100
33const TM_STATIC_NUM: i64 = 50 // a bin is static when it falls below this percent of the median. A FRACTION not a percentile: tm_percentile returns a bucket representative, so the bottom quartile is not strictly below p25 and a percentile threshold could never match.
34const TM_STATIC_DEN: i64 = 100
35const TM_MOTION_PCT: i64 = 90 // high-motion self-calibrates to the file p90. MEASURED 2026-07-31: the fixed 160-percent-of-median sat ABOVE THE MAXIMUM BIN on 8 of 10 real files, so ts_motion_marks could never fire on this corpus. // a rhythmic segment must span >= this (sustained beat, not a couple of pulses)

functions

37func tm_w32(b: *u8, o: i64, v: i64) -> i64 { b[o]=((v>>24)&0xff) as u8; b[o+1]=((v>>16)&0xff) as u8; b[o+2]=((v>>8)&0xff) as u8; b[o+3]=(v&0xff) as u8; return o+4 }
38func tm_w64(b: *u8, o: i64, v: i64) -> i64 { o=tm_w32(b,o,(v>>32)&0xffffffff); o=tm_w32(b,o,v&0xffffffff); return o }
called by 1: ts_marks_write calls 1: tm_w32
42func tm_median(bins: *i64, nb: i64) -> i64
63func tm_bin_stats(bins: *i64, nb: i64, out: *i64) -> i64
called by 1: main calls 1: tm_median
105func ts_silence_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64
called by 2: mainmain calls 1: tm_median
143func tm_percentile(bins: *i64, nb: i64, p: i64) -> i64
179func ts_static_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64
called by 2: mainmain calls 2: tm_mediantm_percentile
217func ts_motion_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64
called by 2: mainmain calls 2: tm_mediantm_percentile
253func ts_scene_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64
called by 2: mainmain calls 1: tm_median
274func tm_window_rhythmic(bins: *i64, w: i64, W: i64) -> i64
called by 1: ts_rhythm_marks
296func ts_rhythm_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64
called by 3: mainmainmain calls 1: tm_window_rhythmic
333func ts_classify(mtype: *i64, mstart: *i64, mend: *i64, nmarks: i64, dur_ms: i64, out: *i64) -> i64
362func ts_marks_write(ob: *u8, o: i64, mtype: *i64, mstart: *i64, mend: *i64, nm: i64) -> i64
called by 1: main calls 2: tm_w64tm_w32