Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mp4/blob/main/src/main.om # omega-mp4 omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mp4 / src / main.om` 179 lines ยท 2903 bytes Raw Blame History 1 note src/main.om: the ovideo command line. 2 note ovideo info FILE [DEPTH] box tree to DEPTH (0..16, default 16), movie and track fields 3 note ovideo dump FILE one line per sample (test aid; values in media ticks) 4 note ovideo trim IN START END OUT lossless cut, START and END times 5 note ovideo join OUT A B ... lossless concatenation of 2..16 inputs 6 note A time is decimal seconds (digits, optional "." and up to 9 fraction digits) that must be an 7 note exact number of ticks of the movie timescale (mvhd), else usage (1); or "@N", N movie ticks. 8 note No floating point is used, so the edit boundary is exact. 9 text minfo "info" 10 text mdump "dump" 11 text mtrim "trim" 12 text mjoin "join" 13 fn meq a view uchar * b view uchar * to bool 14 if ne len a len b 15 ret false 16 end 17 for i ulong len a bound 4096 18 if ne get a i get b i 19 ret false 20 end 21 end 22 ret true 23 end 24 fn mtime arg ulong scale ulong to ulong 25 b = new uchar 64 0 26 r = argread arg b 0 64 27 if or le r 0 gt r 30 28 quit 1 eusage 29 end 30 n = ulong r 31 i = ulong 0 32 exact = false 33 if eq get b 0 64 34 exact = true 35 i = 1 36 end 37 v = ulong 0 38 d = ulong 1 39 dotted = false 40 digits = ulong 0 41 while lt i n bound 64 42 c = ulong get b i 43 i = add i 1 44 if eq c 46 45 if or dotted exact 46 quit 1 eusage 47 end 48 dotted = true 49 continue 50 end 51 if or lt c 48 gt c 57 52 quit 1 eusage 53 end 54 if gt v `922337203685477579` 55 quit 34 ebound 56 end 57 v = add mul v 10 sub c 48 58 digits = add digits 1 59 if dotted 60 if ge d `1000000000` 61 quit 1 eusage 62 end 63 d = mul d 10 64 end 65 end 66 if eq digits 0 67 quit 1 eusage 68 end 69 if exact 70 ret v 71 end 72 if eq scale 0 73 quit 23 etable 74 end 75 if gt v div `9223372036854775807` scale 76 quit 34 ebound 77 end 78 v = mul v scale 79 if ne rem v d 0 80 quit 1 eusage 81 end 82 ret div v d 83 end 84 fn mout arg ulong to void 85 r = argread arg opath 0 4096 86 if le r 0 87 quit 1 eusage 88 end 89 put opl 0 ulong r 90 end 91 fn mmedia f ulong to void 92 base = fget f FTK0 93 for t ulong fget f FNTK bound 8 94 if eq tg add base t KKEEP 0 95 quit 32 eother 96 end 97 end 98 end 99 fn mload arg ulong f ulong to void 100 openin arg f 101 bparse f 102 put nfl 0 add f 1 103 end 104 fn mclose to void 105 oflush 106 for f ulong get nfl 0 bound 16 107 r = fclose get ffd f 108 end 109 end 110 fn main to int 111 b = new uchar 32 0 112 n = ulong argcnt 113 if lt n 3 114 quit 1 eusage 115 end 116 r = argread 1 b 0 32 117 if le r 0 118 quit 1 eusage 119 end 120 if meq part b 0 ulong r minfo 121 if and ne n 3 ne n 4 122 quit 1 eusage 123 end 124 mload 2 0 125 depth = ulong 16 126 if eq n 4 127 depth = mtime 3 1 128 if gt depth 16 129 quit 1 eusage 130 end 131 end 132 iinfo 0 depth 133 mclose 134 ret 0 135 end 136 if meq part b 0 ulong r mdump 137 if ne n 3 138 quit 1 eusage 139 end 140 mload 2 0 141 idump 0 142 mclose 143 ret 0 144 end 145 if meq part b 0 ulong r mtrim 146 if ne n 6 147 quit 1 eusage 148 end 149 mload 2 0 150 mmedia 0 151 start = mtime 3 fget 0 FMTS 152 finish = mtime 4 fget 0 FMTS 153 mout 5 154 ptrim 0 start finish 155 woutput 156 mclose 157 ret 0 158 end 159 if meq part b 0 ulong r mjoin 160 if lt n 5 161 quit 1 eusage 162 end 163 count = sub n 3 164 if gt count NF 165 quit 34 ebound 166 end 167 for f ulong count bound 16 168 mload add f 3 f 169 mmedia f 170 end 171 mout 2 172 pjoin count 173 woutput 174 mclose 175 ret 0 176 end 177 quit 1 eusage 178 ret 1 179 end