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 / main.om

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