[Durian-svn] [3760] script to detect incorrect animation lengths

campbell institute at blender.org
Mon May 24 07:54:05 CEST 2010


Revision: 3760
          https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=3760
Author:   campbell
Date:     2010-05-24 07:54:05 +0200 (Mon, 24 May 2010)
Log Message:
-----------
script to detect incorrect animation lengths

Added Paths:
-----------
    pro/scripts/utilities/blend_duration_match.py

Added: pro/scripts/utilities/blend_duration_match.py
===================================================================
--- pro/scripts/utilities/blend_duration_match.py	                        (rev 0)
+++ pro/scripts/utilities/blend_duration_match.py	2010-05-24 05:54:05 UTC (rev 3760)
@@ -0,0 +1,153 @@
+#!/usr/bin/python
+
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+# In Blender, selecting scenes in the databrowser (shift+f4) will tag for rendering.
+
+# This struct wont change according to ton.
+# Note that the size differs on 32/64bit
+'''
+typedef struct BHead {
+    int code, len;
+    void *old;
+    int SDNAnr, nr;
+} BHead;
+'''
+
+def read_blend_rend_chunk(path):
+
+    import struct
+
+    file = open(path, 'rb')
+    
+    head = file.read(7)
+
+    if head[0:2] == b'\x1f\x8b': # gzip magic
+        import gzip
+        file.close()
+        file = gzip.open(path, 'rb')
+        head = file.read(7)
+
+    if head != b'BLENDER':
+        print("not a blend file:", path)
+        file.close()
+        return []
+
+    is_64_bit = (file.read(1) == b'-')
+
+    # true for PPC, false for X86
+    is_big_endian = (file.read(1) == b'V')
+
+    # Now read the bhead chunk!!!
+    file.read(3) # skip the version
+
+    scenes = []
+    
+    sizeof_bhead = 24 if is_64_bit else 20
+
+    while file.read(4) == b'REND':
+        sizeof_bhead_left = sizeof_bhead - 4
+        
+        rend_length = struct.unpack('>i' if is_big_endian else '<i', file.read(4))[0]
+        sizeof_bhead_left -= 4
+
+        # We dont care about the rest of the bhead struct
+        file.read(sizeof_bhead_left)
+        
+        # Now we want the scene name, start and end frame. this is 32bites long
+        start_frame, end_frame = struct.unpack('>2i' if is_big_endian else '<2i', file.read(8))
+
+        scene_name = file.read(24)
+
+        scene_name = scene_name[:scene_name.index(b'\0')]
+
+        try:
+            scene_name = str(scene_name, 'utf8')
+        except TypeError:
+            pass
+
+        scenes.append((start_frame, end_frame, scene_name))
+
+    return scenes
+
+
+def main():
+    import sys
+    for arg in sys.argv[1:]:
+        if arg.lower().endswith('.blend'):
+            for value in read_blend_rend_chunk(arg):
+                print("%d %d %s" % value)
+
+#if __name__ == '__main__':
+#    main()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import os
+
+def file_list(path):
+    for dirpath, dirnames, filenames in os.walk(path):
+        for filename in filenames:
+            yield os.path.join(dirpath, filename)
+
+
+def main():
+
+    for f in sorted(file_list("/d/pro/scenes")):
+        if f.endswith(".blend"):
+            if not f.endswith("_comp.blend"):
+                f_comp = f.replace(".blend", "_comp.blend")
+                if os.path.exists(f_comp):
+                    # compare
+                    start_frame_ani, end_frame_ani, scene_name_ani = read_blend_rend_chunk(f)[0]
+                    start_frame_cmp, end_frame_cmp, scene_name_cmp = read_blend_rend_chunk(f_comp)[0]
+                    
+                    if start_frame_ani != start_frame_cmp and end_frame_ani != scene_name_cmp:
+                        print("*mismatch*: %s: %s(%d-%d) vs %s(%d-%d)" % (f, scene_name_ani, start_frame_ani, end_frame_ani, scene_name_cmp, start_frame_cmp, end_frame_cmp))
+                    else:
+                        print("matching: %s" % f)
+
+if __name__ == '__main__':
+    main()



More information about the Durian-svn mailing list