#!/usr/bin/env python3 """Count animation frames in a binary FBX (Kaydara 7.x). Parses the node tree, reads AnimationCurve KeyTime arrays; frames = max key count. Also reports the AnimationStack time span as a cross-check.""" import struct, zlib, sys FBX_KTIME = 46186158000 # ktime units per second def parse(path): d = open(path, "rb").read() assert d[:21] == b"Kaydara FBX Binary \x00", "not a binary FBX" version = struct.unpack("= 7500 pos = 27 keytime_lens = [] stack_span = [0] def read_prop(p): t = chr(d[p]); p += 1 if t in "YCIFDL": sz = {"Y":2,"C":1,"I":4,"F":4,"D":8,"L":8}[t] val = None if t=="L": val = struct.unpack(" keyframe count if name == b"KeyTime": for kind,t,v in props: if kind=="array": keytime_lens.append(v) # AnimationStack LocalStop (int64 ktime) via Properties70 "P" records if name == b"P" and props and props[0][2] in (b"LocalStop", b"LocalStop|LocalStop"): for kind,t,v in props: if kind=="scalar" and t=="L" and v: stack_span[0]=max(stack_span[0], v) # recurse into nested nodes until `end` while p < end - (13 if not u64 else 25): child, p = read_node(p) if child is None: break p = end return name, p footer = len(d) - 160 while pos < footer: node, pos = read_node(pos) if node is None: break return { "version": version, "keys_max": max(keytime_lens) if keytime_lens else 0, "span_frames": round(stack_span[0]/FBX_KTIME*30) if stack_span[0] else 0, } if __name__ == "__main__": for f in sys.argv[1:]: try: r = parse(f) print("%-45s keys=%-5s span30=%-5s ver=%s" % (f.split('/')[-1], r["keys_max"], r["span_frames"], r["version"])) except Exception as e: print("%-45s ERR %s" % (f.split('/')[-1], e))