omega-mp4
omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0)
Brought by drakestapleton
| 1 | note omega-mp4 (command ovideo), src/info.om: the info and dump commands. Entries: iinfo f dp and |
| 2 | note idump f, both after openin and bparse of file f. Helpers start with i, texts with ix. Output goes |
| 3 | note through the io.om standard output buffer (obyte, ostr, onum, osnum, ofourcc), flushed at the end. |
| 4 | note Line formats (single spaces; T the zero-based track of the file, in trak order; I a zero-based |
| 5 | note index; numbers decimal; a fourcc is its 4 bytes, a byte outside 32 .. 126 printed as '?'): |
| 6 | note file size=Z ftyp=P+S moov=P+S mvhd=P+S version=V mdat=P mdats=N moovpos=front|end |
| 7 | note movie timescale=TS duration=D tracks=N |
| 8 | note track T id=ID handler=XXXX codec=XXXX timescale=TS duration=D samples=N sync=S ctts=0|1 co=32|64 edits=E keep=0|1 editform=simple|complex |
| 9 | note loc T trak=P+S tkhd=P+S mdhd=P+S hdlr=P+S minf=XXXX:P+S stbl=P+S stsd=P+S tkdur=D first=K chunks=C |
| 10 | note edit T I duration=D media_time=M rate=R |
| 11 | note editn T empty=E0 media_time=MT duration=ED |
| 12 | note box XXXX offset=P size=S header=H |
| 13 | note file: mdat is the first mdat payload offset; moovpos is front when the moov box starts before the |
| 14 | note first mdat box (or there is no mdat), else end. |
| 15 | note movie: mvhd timescale and duration (14496-12 8.2.2) and the trak count. track: tkhd track_ID |
| 16 | note (8.3.2), hdlr handler_type (8.4.3), the stsd entry type (8.5.2), mdhd timescale and duration |
| 17 | note (8.4.2, media ticks), stsz sample_count (8.7.3), the stss entry count or every sample when there |
| 18 | note is no stss (8.6.2), ctts present (8.6.1.3), stco 32 or co64 64 (8.7.5), elst entry_count (8.6.6), |
| 19 | note keep 1 for vide and soun, editform complex when KEDM is 2 (box.om bedit), else simple (no edit |
| 20 | note list, or [one empty edit] + one media edit). loc: each box as offset+size (whole box, 0+0 when |
| 21 | note absent), the media header type (????:0+0 when absent), the tkhd duration in movie ticks, the first |
| 22 | note global sample and the chunk count. edit: each elst entry (segment_duration in movie ticks, |
| 23 | note media_time in media ticks, -1 for an empty edit, media rate as fixed 16.16). editn: the |
| 24 | note normalized edit (box.om bedit; all 0 for a complex list). |
| 25 | note box: the box tree in file order, indented two spaces per level, levels 0 .. dp - 1 (dp 0: no |
| 26 | note tree; dp above 16: refused 34). Only moov, trak, edts, mdia, minf, dinf and stbl are opened. |
| 27 | note idump prints one line per sample, track after track in decode order, and nothing else: |
| 28 | note sample T I DTS CTO DUR SIZE OFFSET SYNC |
| 29 | note (media ticks; CTO signed; SYNC 0 or 1). |
| 30 | text ixfile "file size=" |
| 31 | text ixftyp " ftyp=" |
| 32 | text ixmoov " moov=" |
| 33 | text ixmvhd " mvhd=" |
| 34 | text ixver " version=" |
| 35 | text ixmdat " mdat=" |
| 36 | text ixmdats " mdats=" |
| 37 | text ixpos " moovpos=" |
| 38 | text ixfront "front" |
| 39 | text ixend "end" |
| 40 | text ixmovie "movie timescale=" |
| 41 | text ixdur " duration=" |
| 42 | text ixtrks " tracks=" |
| 43 | text ixtrack "track " |
| 44 | text ixid " id=" |
| 45 | text ixhdlr " handler=" |
| 46 | text ixcodec " codec=" |
| 47 | text ixts " timescale=" |
| 48 | text ixsamp " samples=" |
| 49 | text ixsync " sync=" |
| 50 | text ixctts " ctts=" |
| 51 | text ixco " co=" |
| 52 | text ixedits " edits=" |
| 53 | text ixkeep " keep=" |
| 54 | text ixform " editform=" |
| 55 | text ixsimple "simple" |
| 56 | text ixcplx "complex" |
| 57 | text ixloc "loc " |
| 58 | text ixtrak " trak=" |
| 59 | text ixtkhd " tkhd=" |
| 60 | text ixmdhd " mdhd=" |
| 61 | text ixhdlb " hdlr=" |
| 62 | text ixminf " minf=" |
| 63 | text ixstbl " stbl=" |
| 64 | text ixstsd " stsd=" |
| 65 | text ixtkdur " tkdur=" |
| 66 | text ixfirst " first=" |
| 67 | text ixchunk " chunks=" |
| 68 | text ixedit "edit " |
| 69 | text ixmt " media_time=" |
| 70 | text ixrate " rate=" |
| 71 | text ixeditn "editn " |
| 72 | text ixempty " empty=" |
| 73 | text ixbox "box " |
| 74 | text ixoff " offset=" |
| 75 | text ixsize " size=" |
| 76 | text ixhead " header=" |
| 77 | text ixsampl "sample " |
| 78 | |
| 79 | note ---- info ---- |
| 80 | fn iinfo f ulong dp ulong to void |
| 81 | if gt dp ND |
| 82 | quit 34 edepth |
| 83 | end |
| 84 | ifile f |
| 85 | n = fget f FNTK |
| 86 | for t ulong n bound 8 |
| 87 | itrack f t |
| 88 | end |
| 89 | if gt dp 0 |
| 90 | put nbox 0 0 |
| 91 | itree f 0 fget f FSZ 0 dp |
| 92 | end |
| 93 | oflush |
| 94 | end |
| 95 | |
| 96 | note ipair: P+S. |
| 97 | fn ipair p ulong s ulong to void |
| 98 | onum p |
| 99 | obyte 43 |
| 100 | onum s |
| 101 | end |
| 102 | |
| 103 | fn ifile f ulong to void |
| 104 | ostr ixfile |
| 105 | onum fget f FSZ |
| 106 | ostr ixftyp |
| 107 | ipair fget f FFTP fget f FFTS |
| 108 | ostr ixmoov |
| 109 | ipair fget f FMOOVP fget f FMOOVS |
| 110 | ostr ixmvhd |
| 111 | ipair fget f FMVP fget f FMVS |
| 112 | ostr ixver |
| 113 | onum fget f FMVV |
| 114 | ostr ixmdat |
| 115 | onum fget f FMDATP |
| 116 | ostr ixmdats |
| 117 | onum fget f FNMDAT |
| 118 | ostr ixpos |
| 119 | ipos f |
| 120 | obyte 10 |
| 121 | ostr ixmovie |
| 122 | onum fget f FMTS |
| 123 | ostr ixdur |
| 124 | onum fget f FMDUR |
| 125 | ostr ixtrks |
| 126 | onum fget f FNTK |
| 127 | obyte 10 |
| 128 | end |
| 129 | |
| 130 | note ipos: front when moov starts before the first mdat box, else end; front without an mdat. A box |
| 131 | note never starts inside another box's header, so moov before the first mdat payload (FMDATP) is the |
| 132 | note same as moov before the first mdat box. |
| 133 | fn ipos f ulong to void |
| 134 | if eq fget f FNMDAT 0 |
| 135 | ostr ixfront |
| 136 | ret |
| 137 | end |
| 138 | if lt fget f FMOOVP fget f FMDATP |
| 139 | ostr ixfront |
| 140 | else |
| 141 | ostr ixend |
| 142 | end |
| 143 | end |
| 144 | |
| 145 | note itrack: the track line, then its loc, edit and editn lines. |
| 146 | fn itrack f ulong t ulong to void |
| 147 | sl = add fget f FTK0 t |
| 148 | ostr ixtrack |
| 149 | onum t |
| 150 | ostr ixid |
| 151 | onum tg sl KTID |
| 152 | ostr ixhdlr |
| 153 | ofourcc tg sl KHDLR |
| 154 | ostr ixcodec |
| 155 | ofourcc tg sl KCC |
| 156 | ostr ixts |
| 157 | onum tg sl KTS |
| 158 | ostr ixdur |
| 159 | onum tg sl KMDUR |
| 160 | ostr ixsamp |
| 161 | onum tg sl KNS |
| 162 | ostr ixsync |
| 163 | onum tg sl KNSYN |
| 164 | ostr ixctts |
| 165 | onum tg sl KCTTS |
| 166 | ostr ixco |
| 167 | onum tg sl KCO |
| 168 | ostr ixedits |
| 169 | onum tg sl KNE |
| 170 | ostr ixkeep |
| 171 | onum tg sl KKEEP |
| 172 | ostr ixform |
| 173 | if eq tg sl KEDM 2 |
| 174 | ostr ixcplx |
| 175 | else |
| 176 | ostr ixsimple |
| 177 | end |
| 178 | obyte 10 |
| 179 | ilocs t sl |
| 180 | iedits t sl |
| 181 | end |
| 182 | |
| 183 | fn ilocs t ulong sl ulong to void |
| 184 | ostr ixloc |
| 185 | onum t |
| 186 | ostr ixtrak |
| 187 | ipair tg sl KTRKP tg sl KTRKS |
| 188 | ostr ixtkhd |
| 189 | ipair tg sl KTKP tg sl KTKS |
| 190 | ostr ixmdhd |
| 191 | ipair tg sl KMDHP tg sl KMDHS |
| 192 | ostr ixhdlb |
| 193 | ipair tg sl KHDLP tg sl KHDLS |
| 194 | ostr ixminf |
| 195 | ofourcc tg sl KMINH |
| 196 | obyte 58 |
| 197 | ipair tg sl KMINP tg sl KMINS |
| 198 | ostr ixstbl |
| 199 | ipair tg sl KSTBP tg sl KSTBS |
| 200 | ostr ixstsd |
| 201 | ipair tg sl KSDP tg sl KSDS |
| 202 | ostr ixtkdur |
| 203 | onum tg sl KTKD |
| 204 | ostr ixfirst |
| 205 | onum tg sl KSB |
| 206 | ostr ixchunk |
| 207 | onum tg sl KNCH |
| 208 | obyte 10 |
| 209 | end |
| 210 | |
| 211 | note iedits: the elst entries as read (at most NE), then the normalized edit. |
| 212 | fn iedits t ulong sl ulong to void |
| 213 | c = tg sl KNE |
| 214 | b = mul sl 64 |
| 215 | for i ulong c bound 64 |
| 216 | ostr ixedit |
| 217 | onum t |
| 218 | obyte 32 |
| 219 | onum i |
| 220 | ostr ixdur |
| 221 | onum get eld add b i |
| 222 | ostr ixmt |
| 223 | osnum get elm add b i |
| 224 | ostr ixrate |
| 225 | onum get elr add b i |
| 226 | obyte 10 |
| 227 | end |
| 228 | ostr ixeditn |
| 229 | onum t |
| 230 | ostr ixempty |
| 231 | onum tg sl KE0 |
| 232 | ostr ixmt |
| 233 | onum tg sl KMT |
| 234 | ostr ixdur |
| 235 | onum tg sl KED |
| 236 | obyte 10 |
| 237 | end |
| 238 | |
| 239 | note icont: the container boxes the tree opens: moov (8.2.1), trak (8.3.1), edts (8.6.5), mdia |
| 240 | note (8.4.1), minf (8.4.4), dinf (8.7.1), stbl (8.5.1). Their payload is boxes only. |
| 241 | fn icont t ulong to ulong |
| 242 | if or eq t BMOOV eq t BTRAK |
| 243 | ret 1 |
| 244 | end |
| 245 | if or eq t BEDTS eq t BMDIA |
| 246 | ret 1 |
| 247 | end |
| 248 | if or eq t BMINF eq t BDINF |
| 249 | ret 1 |
| 250 | end |
| 251 | if eq t BSTBL |
| 252 | ret 1 |
| 253 | end |
| 254 | ret 0 |
| 255 | end |
| 256 | |
| 257 | note itree: the boxes in [a, e) at level d, each header checked by bhdr (box.om; 65536 boxes per |
| 258 | note walk); a container below level m - 1 is opened. The recursion depth is at most m (<= 16). |
| 259 | fn itree f ulong a ulong e ulong d ulong m ulong to void |
| 260 | p = a |
| 261 | while lt p e bound 65537 |
| 262 | bhdr f p e |
| 263 | t = get bhd 0 |
| 264 | h = get bhd 1 |
| 265 | s = get bhd 2 |
| 266 | for i ulong d bound 16 |
| 267 | obyte 32 |
| 268 | obyte 32 |
| 269 | end |
| 270 | ostr ixbox |
| 271 | ofourcc t |
| 272 | ostr ixoff |
| 273 | onum p |
| 274 | ostr ixsize |
| 275 | onum s |
| 276 | ostr ixhead |
| 277 | onum h |
| 278 | obyte 10 |
| 279 | if eq icont t 1 |
| 280 | if lt add d 1 m |
| 281 | itree f add p h add p s add d 1 m |
| 282 | end |
| 283 | end |
| 284 | p = add p s |
| 285 | end |
| 286 | end |
| 287 | |
| 288 | note ---- dump ---- |
| 289 | fn idump f ulong to void |
| 290 | n = fget f FNTK |
| 291 | for t ulong n bound 8 |
| 292 | sl = add fget f FTK0 t |
| 293 | b = tg sl KSB |
| 294 | c = tg sl KNS |
| 295 | for i ulong c bound 1048576 |
| 296 | isample t i add b i |
| 297 | end |
| 298 | end |
| 299 | oflush |
| 300 | end |
| 301 | |
| 302 | note isample: global sample g as sample T I DTS CTO DUR SIZE OFFSET SYNC. |
| 303 | fn isample t ulong i ulong g ulong to void |
| 304 | ostr ixsampl |
| 305 | onum t |
| 306 | obyte 32 |
| 307 | onum i |
| 308 | obyte 32 |
| 309 | onum get sdts g |
| 310 | obyte 32 |
| 311 | osnum get scto g |
| 312 | obyte 32 |
| 313 | onum ulong get sdur g |
| 314 | obyte 32 |
| 315 | onum ulong get ssz g |
| 316 | obyte 32 |
| 317 | onum get soff g |
| 318 | obyte 32 |
| 319 | onum ulong get ssync g |
| 320 | obyte 10 |
| 321 | end |