nx_ts_marks.nx
buildroot/runtime/nx_ts_marks.nx
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
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
| 14 | const TM_MAGIC_60000: i64 = 60000 |
| 17 | const TM_BIN_MS: i64 = 500 // audio-byte accumulation window |
| 18 | const TM_SIL_NUM: i64 = 15 // silent if bin < median * 15/100 (15% of typical loudness) |
| 19 | const TM_SIL_DEN: i64 = 100 |
| 20 | const TM_MIN_DEADAIR_MS: i64 = 1500 // a run must span >= this to count as dead air (not a normal pause) |
| 21 | const TM_MOTION_NUM: i64 = 160 // high-motion if a video-byte window > 160% of the median window (P-frame bitrate = motion) |
| 22 | const TM_MOTION_DEN: i64 = 100 |
| 23 | const TM_MIN_MOTION_MS: i64 = 1500 // a high-motion run must span >= this (sustained activity, not a single spike) |
| 24 | const TM_SCENE_NUM: i64 = 200 // scene-cut if a window > 200% of the PREVIOUS window (prediction reset at a cut) |
| 25 | const TM_SCENE_DEN: i64 = 100 |
| 26 | const TM_RHYTHM_NUM: i64 = 60 // rhythmic if the best autocorrelation peak >= 60% of lag-0 energy (strong periodicity) |
| 27 | const TM_RHYTHM_DEN: i64 = 100 |
| 28 | const TM_MIN_RHYTHM_MS: i64 = 4000 |
| 29 | const 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). |
| 30 | const TM_MIN_STATIC_MS: i64 = 3000 // a static run must span >= this to be worth cutting; shorter is a normal pause |
| 31 | const 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 |
| 32 | const TM_STATIC_GUARD_DEN: i64 = 100 |
| 33 | const 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. |
| 34 | const TM_STATIC_DEN: i64 = 100 |
| 35 | const 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
| 37 | func 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 } |
| 38 | func 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 } |
| 42 | func tm_median(bins: *i64, nb: i64) -> i64 called by 5: tm_bin_statsts_silence_marksts_static_marksts_motion_marksts_scene_marks calls 1: sys_mmap |
| 63 | func tm_bin_stats(bins: *i64, nb: i64, out: *i64) -> i64 |
| 105 | func ts_silence_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64 |
| 143 | func tm_percentile(bins: *i64, nb: i64, p: i64) -> i64 |
| 179 | func ts_static_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64 |
| 217 | func ts_motion_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64 |
| 253 | func ts_scene_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64 |
| 274 | func tm_window_rhythmic(bins: *i64, w: i64, W: i64) -> i64 called by 1: ts_rhythm_marks |
| 296 | func ts_rhythm_marks(bins: *i64, nb: i64, bin_ms: i64, mtype: *i64, mstart: *i64, mend: *i64, cap: i64) -> i64 |
| 333 | func ts_classify(mtype: *i64, mstart: *i64, mend: *i64, nmarks: i64, dur_ms: i64, out: *i64) -> i64 |
| 362 | func ts_marks_write(ob: *u8, o: i64, mtype: *i64, mstart: *i64, mend: *i64, nm: i64) -> i64 |