interplane.Get Omega
Read in your language

omega-mp4

omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0)

Brought by drakestapleton

branch main Branches Tags History

omega-mp4 / src / info.om

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