History

add extra/ivf2raw

Sigrid Solveig Haflínudóttir committed 5 years ago

Commit bbba27d1 parent ad7fba12 files · +117 −0Browse files

Unified · Split

2 files
  1. extra/ivf2raw.c +109 −0
  2. extra/mkfile +8 −0
extra/ivf2raw.c+109−0
@@ -0,0 +1,109 @@
1#include <u.h>
2#include <libc.h>
3#include <bio.h>
4
5static int
6Bu16le(Biobuf *b, u16int *o)
7{
8 int x;
9
10 x = Bgetc(b);
11 x |= Bgetc(b)<<8;
12 *o = x;
13 if(x < 0)
14 werrstr("failed to read 2 bytes");
15
16 return x < 0 ? -1 : 0;
17}
18
19static int
20Bu32le(Biobuf *b, u32int *o)
21{
22 int x, i;
23
24 *o = 0;
25 for(i = 0; i < 4; *o |= x<<(i*8), i++){
26 if((x = Bgetc(b)) < 0){
27 werrstr("failed to read 4 bytes");
28 return -1;
29 }
30 }
31
32 return 0;
33}
34
35static int
36Bu64le(Biobuf *b, u64int *o)
37{
38 int x, i;
39
40 *o = 0;
41 for(i = 0; i < 8; *o |= x<<(i*8), i++){
42 if((x = Bgetc(b)) < 0){
43 werrstr("failed to read 8 bytes");
44 return -1;
45 }
46 }
47
48 return 0;
49}
50
51static void
52usage(void)
53{
54 fprint(2, "usage: %s <file.ivf >file.raw\n", argv0);
55 exits("usage");
56}
57
58void
59main(int argc, char **argv)
60{
61 int n, bufsz, framenum;
62 u32int tbnum, tbdenum;
63 u16int w, h, hlen;
64 u64int timestamp;
65 Biobuf in, out;
66 char tmp[6];
67 u8int *buf;
68 u32int sz;
69
70 ARGBEGIN{
71 }ARGEND
72
73 if(argc != 0)
74 usage();
75
76 Binit(&in, 0, OREAD);
77 Binit(&out, 1, OWRITE);
78
79 if(Bread(&in, tmp, 6) != 6 || Bu16le(&in, &hlen) < 0)
80 sysfatal("header read failed");
81 if(memcmp(tmp, "DKIF", 4) != 0)
82 sysfatal("expected DKIF, got %02x%02x%02x%02x", tmp[0], tmp[1], tmp[2], tmp[3]);
83 if(hlen < 0x20 || Bread(&in, tmp, 4) != 4)
84 sysfatal("invalid header: hlen=%d", hlen);
85 if(Bu16le(&in, &w) < 0 || Bu16le(&in, &h) < 0 || Bu32le(&in, &tbdenum) < 0 || Bu32le(&in, &tbnum) < 0)
86 sysfatal("invalid header: %r");
87 if(Bseek(&in, hlen, 0) != hlen)
88 sysfatal("invalid IVF stream");
89
90 bufsz = 0;
91 buf = nil;
92 for(framenum = 0;; framenum++){
93 if(Bu32le(&in, &sz) < 0 || Bu64le(&in, &timestamp) || (int)sz < 0)
94 break;
95 if(bufsz < sz){
96 bufsz = sz;
97 if((buf = realloc(buf, bufsz)) == nil)
98 sysfatal("frame %d is too big: %d bytes", framenum, bufsz);
99 }
100 if((n = Bread(&in, buf, sz)) != sz)
101 sysfatal("short read (%d < %d)", n, sz);
102 Bwrite(&out, buf, sz);
103 }
104
105 Bterm(&in);
106 Bterm(&out);
107
108 exits(nil);
109}
extra/mkfile+8−0
@@ -0,0 +1,8 @@
1</$objtype/mkfile
2
3TARG=ivf2raw
4BIN=/$objtype/bin
5
6default:V: all
7
8</sys/src/cmd/mkmany

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t