-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslice.py
46 lines (32 loc) · 943 Bytes
/
slice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import os
if len(sys.argv) != 3:
print "Usage: %s <file> <frames per slice>" % sys.argv[0]
sys.exit(-1)
ifilename = sys.argv[1]
ifile = open(ifilename, 'r')
frames_per_slice = int(sys.argv[2])
cur_slice = 0
while True:
print "Slice %d" % cur_slice
ofiles = []
directory = 'dump/%04d' % cur_slice
if not os.path.exists(directory):
os.makedirs(directory)
for i in range(2048):
ofiles.append(open('%s/%04d' % (directory,i), 'w'))
for idx in range(frames_per_slice):
# one frame
block = ifile.read(2048)
if len(block) < 2048:
if len(block) > 0:
print "Warning: found trailing incomplete block with length %d" % len(block)
break
for i,of in enumerate(ofiles):
of.write(block[i])
if len(block) < 2048:
break
for f in ofiles:
f.close()
cur_slice += 1
print "Done."