code wiki / (root) / nx_mp4_faststart.nx

nx_mp4_faststart.nx

buildroot/runtime/nx_mp4_faststart.nx

5387 B92 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic mp4
docsdependenciesstructsconstsfunctions

about

nx_mp4_faststart.nx -- qt-faststart: relocate the moov atom to the FRONT of an mp4 so a browser <video> can stream it progressively over HTTP. A non-faststart mp4 has [ftyp][mdat...][moov] (moov at the END), so the player's first Range read has ftyp+mdat but NO moov (the track/sample tables) -> "no video, this format is not supported". Moving moov before mdat fixes it. LOSSLESS: no transcode; the ONLY mutation is rewriting each stco (32-bit) / co64 (64-bit) chunk offset by +moov_size, because inserting moov after ftyp shifts every byte of mdat forward by exactly moov_size. Reads argv[1] (the mp4), writes the faststart mp4 to stdout (fd 1). If the file is ALREADY faststart (moov before mdat) or has no moov, it is copied verbatim (safe no-op). license_tier: ORIGINAL No hw writes (Rule 26). module: nishi-core.torrent.mp4_faststart

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_mp4_faststart.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_exit sys_openat_rd sys_lseek sys_mmap sys_read fs_be32 fs_be64 fs_teq fs_emit sys_lseek ↻ sys_read ↻ sys_write sys_close fs_adjust fs_be32 ↻ fs_be64 ↻ fs_iscont fs_teq ↻ fs_adjust ↻ fs_teq ↻ fs_put32 fs_put64 sys_write ↻

structs

none

consts

11const FS_RD: i64 = 262144

functions

13func fs_be32(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<24)|((b[o+1] as i64)<<16)|((b[o+2] as i64)<<8)|(b[o+3] as i64) }
called by 2: fs_adjustmain
14func fs_be64(b: *u8, o: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=(v<<8)|(b[o+i] as i64); i=i+1 } return v }
called by 2: fs_adjustmain
15func fs_put32(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 0 }
called by 1: fs_adjust
16func fs_put64(b: *u8, o: i64, v: i64) -> i64 { var i: i64=0; while i<8 { b[o+7-i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
called by 1: fs_adjust
17func fs_teq(b: *u8, o: i64, t: *u8) -> i64 { var i: i64=0; while i<4 { if b[o+i]!=t[i] { return 0 } i=i+1 } return 1 }
18func fs_iscont(b: *u8, o: i64) -> i64
called by 1: fs_adjust calls 1: fs_teq
26func fs_adjust(m: *u8, start: i64, end: i64, shift: i64) -> i64
51func fs_emit(fd: i64, start: i64, len: i64, buf: *u8) -> i64
called by 1: main calls 3: sys_lseeksys_readsys_write
57func main(argc: i64, argv: *i64) -> i64