nx_video_codec.nx
buildroot/runtime/nx_video_codec.nx
about
nx_video_codec.nx -- NishiVideo v1: I-frame intra-coded video codec.
Composes nx_dct8 + uniform quantisation + nx_video_frame. No P/B
frames in v1; one frame stands alone, deterministic, audit-replayable.
Pipeline (encode):
pixel block (8x8 i64, range 0..255 luma)
-> subtract 128 (centre on zero per JPEG convention)
-> nx_dct8_forward_2d -> 64 frequency coefficients
-> quantise: coeff_q = round(coeff / quant_step)
-> pack as 64 int16 LE
For a multi-block frame, concatenate per-block payloads.
Then nx_vid_build_header + payload.
Decode reverses: parse header -> for each block, unpack int16
coefficients -> dequantise (multiply by quant_step) -> IDCT -> add
back 128 -> clamp to 0..255 -> output pixel block.
Honest verdict vs Jitsi/Discord/Zoom (the codecs they use):
WIN_axes: deterministic, audit-replayable (hash chain), patent-clean,
refuses BAD_MAGIC frames cleanly (no silent corruption)
LOSE_axes: rate-distortion at parity bitrate (no motion compensation
in v1; no entropy coding yet; quantisation is uniform
not perceptually-weighted)
Named improvements queued: nx_motion_compensation, nx_zigzag_scan,
nx_rle_coefficients, nx_range_code_coefficients,
nx_chroma_subsample, nx_perceptual_quant_table.
genealogy_id: nx_dct8_q10 + nx_video_frame_q10 + jpeg_iso_10918 +
nx_voice_codec_v1_q10
lineage_id: nishi_video_codec_v1_q10
dependencies 7 imports · 1 importers
imports: nx_syscalls.nxnx_dct8.nxnx_video_frame.nxnx_zigzag.nxnx_rle.nxnx_quant_table.nxnx_deblock.nx
imported by: nx_video_codec_v1_adapter.nx
structs
| 69 | struct VideoCodecState |
consts
| 48 | const NX_VID_FLAG_ENTROPY: i64 = 128 |
| 50 | const NX_VID_FLAG_DEBLOCK: i64 = 32 |
| 53 | const NX_VID_FLAG_MOTION: i64 = 16 |
| 54 | const NX_VID_MVR: i64 = 7 // motion search range +/-7 px (4-bit dx,dy) |
| 59 | const NX_VID_FLAG_PERCEPTUAL_QUANT: i64 = 128 |
| 61 | const NX_VC_VID_VERDICT_UNKNOWN: i64 = 0 |
| 62 | const NX_VC_VID_VERDICT_OK: i64 = 1 |
| 63 | const NX_VC_VID_VERDICT_BUF_TOO_SMALL: i64 = 2 |
| 64 | const NX_VC_VID_VERDICT_BAD_PARAMS: i64 = 3 |
| 65 | const NX_VC_VID_VERDICT_FRAME_REJECTED: i64 = 4 |
| 66 | const NX_VC_VID_VERDICT_N: i64 = 5 |
functions
| 98 | func nx_vc_vid_init( |
| 136 | func nx_vc_vid_init_entropy( calls 1: nx_zigzag_init |
| 153 | func nx_vc_vid_set_perceptual_quant( calls 1: nx_qt_luma |
| 169 | func nx_vc_vid_set_deblock(s: *VideoCodecState, enabled: i64) -> i64 |
| 180 | func nx_vc_vid_set_reference(s: *VideoCodecState, ref: *i64) -> i64 |
| 189 | func nx_vc_vid_set_mvr(s: *VideoCodecState, mvr: i64) -> i64 |
| 197 | func nx_vc_vid_set_skip(s: *VideoCodecState, enabled: i64) -> i64 |
| 205 | func _qstep_for(s: *VideoCodecState, idx: i64) -> i64 called by 1: nx_vc_vid_encode |
| 213 | func _w16(buf: *u8, off: i64, v: i64) -> i64 called by 1: nx_vc_vid_encode |
| 221 | func _r16(buf: *u8, off: i64) -> i64 called by 1: nx_vc_vid_decode |
| 231 | func _mv_search(pixels: *i64, ref: *i64, img_w: i64, img_h: i64, called by 1: nx_vc_vid_encode |
| 270 | func nx_vc_vid_encode( |
| 391 | func nx_vc_vid_decode( called by 1: nx_video_codec_v1_decode calls 8: sys_mmapnx_vid_parse_headernx_qt_lumanx_rle_decode_blocknx_zigzag_unscan_r16+2 |
| 518 | func nx_vc_vid_verdict_is_valid(v: i64) -> i64 |