-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Svensson
committed
Apr 18, 2022
0 parents
commit c231241
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
KTX Stats Extractor | ||
------------------- | ||
|
||
Extract embedded JSON statistics to `somedemo.json`: | ||
|
||
``` | ||
./ktx-stats.py somedemo.mvd | ||
``` | ||
|
||
For more details see `stats.c` in the [KTX repository](https://github.com/QW-Group/ktx). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
import struct | ||
import json | ||
import sys | ||
import os | ||
|
||
with open(sys.argv[1], "rb") as fd: | ||
data = fd.read() | ||
|
||
offset = data.rfind(b"\x0a\x00\x00\x03\x00\x00\x00\x00") | ||
offset += 2 | ||
|
||
content = b"" | ||
|
||
while data[offset:offset + 4] == b"\x00\x03\x00\x00": | ||
(length,) = struct.unpack("<H", data[offset+10:offset+12]) | ||
start = offset + 18 | ||
end = start + length - 2 | ||
content += data[start:end] | ||
offset = end | ||
|
||
try: | ||
json.loads(content) | ||
print("success", sys.argv[1]) | ||
(name, _) = os.path.splitext(sys.argv[1]) | ||
|
||
with open(name + ".json", "wb+") as fd: | ||
fd.write(content) | ||
except: | ||
print("failed to load", sys.argv[1]) |