Skip to content

Instantly share code, notes, and snippets.

@rafa-br34
Created January 22, 2024 07:25
Show Gist options
  • Save rafa-br34/c48831fa2b882d29200d15c86f0fbe73 to your computer and use it in GitHub Desktop.
Save rafa-br34/c48831fa2b882d29200d15c86f0fbe73 to your computer and use it in GitHub Desktop.
Simple script to separate images acquired from Spector.js(https://github.com/BabylonJS/Spector.js/) into files.
import base64
import json
import sys
if len(sys.argv) < 3:
print("Expected 2 arguments, capture file, and output folder\n\tpython Separate.py Capture.json Frames/")
exit()
File = open(sys.argv[1], 'r')
Capture = json.loads(File.read())
File.close()
AttachmentIndex = 0
Commands = Capture["commands"]
for Command in Commands:
print("{}/{} ({}%)".format(Command["id"] + 1, len(Commands), int(((Command["id"] + 1) / len(Commands)) * 100)), end='\r')
if "VisualState" in Command and "Attachments" in Command["VisualState"]:
for Attachment in Command["VisualState"]["Attachments"]:
[MediaType, MediaData] = Attachment["src"].split(";")
FileType = MediaType.split("/")[1]
MediaBinary = MediaData.split(",")[1]
NewFile = open(sys.argv[2] + f"{AttachmentIndex}.{FileType}", "wb")
NewFile.write(base64.b64decode(MediaBinary))
NewFile.close()
AttachmentIndex += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment