Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript
2.1 KB
Raw Blame
#!/usr/bin/env python3
"""
Regenerates src/interchange/aaf/template.ts, the embedded AAF "dictionary template".

An AAF file carries the complete AAF meta dictionary (about 1,900 class and type definitions)
plus the Header, Dictionary and Identification objects. Writing those from scratch is pointless
work, so the AAF writer starts from an empty file produced by pyaaf2 (which is known to be
readable by Avid, Premiere Pro and DaVinci Resolve), keeps those objects and replaces the
Content storage with the edit. Run on a developer machine only:

    python3 -m venv /tmp/aafvenv && /tmp/aafvenv/bin/pip install pyaaf2
    /tmp/aafvenv/bin/python packages/core/scripts/gen-aaf-template.py

The output is raw DEFLATE, base64 encoded.
"""
import base64
import os
import sys
import tempfile
import uuid
import zlib

import aaf2

HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, "..", "src", "interchange", "aaf", "template.ts")
PRODUCT_ID = uuid.UUID("5f0b3a8e-4a8c-4e8e-9d2b-0e3c7f6c1a42")

with tempfile.TemporaryDirectory() as tmp:
    path = os.path.join(tmp, "empty.aaf")
    with aaf2.open(path, "w") as f:
        ident = f.header["IdentificationList"].value[0]
        ident["ProductName"].value = "OpenReel"
        ident["CompanyName"].value = "OpenReel"
        ident["ProductVersionString"].value = "1.0"
        ident["ProductID"].value = aaf2.auid.AUID(PRODUCT_ID)
        ident["Platform"].value = "Web"
    data = open(path, "rb").read()

packed = zlib.compressobj(9, zlib.DEFLATED, -15)
raw = packed.compress(data) + packed.flush()
b64 = base64.b64encode(raw).decode("ascii")
lines = [b64[i : i + 120] for i in range(0, len(b64), 120)]
with open(OUT, "w") as out:
    out.write("// Generated by packages/core/scripts/gen-aaf-template.py. Do not edit.\n")
    out.write("// Empty pyaaf2 AAF file (meta dictionary, Header, Dictionary, Identification), raw DEFLATE, base64.\n")
    out.write(f"export const AAF_TEMPLATE_SIZE = {len(data)};\n")
    out.write("export const AAF_TEMPLATE_BASE64 =\n")
    out.write(" +\n".join('  "%s"' % l for l in lines))
    out.write(";\n")
print("wrote", OUT, len(data), "->", len(raw))