@
Build backend images / build content-svc (push) Failing after 19s
Build backend images / build file-svc (push) Failing after 1m53s
Build backend images / build gateway (push) Failing after 16s
Build backend images / build identity-svc (push) Failing after 7m1s
Build backend images / build notification-svc (push) Failing after 7m24s
Build backend images / build render-svc (push) Failing after 3m12s
Build backend images / build studio-svc (push) Failing after 43s
Build backend images / build content-svc (push) Failing after 19s
Build backend images / build file-svc (push) Failing after 1m53s
Build backend images / build gateway (push) Failing after 16s
Build backend images / build identity-svc (push) Failing after 7m1s
Build backend images / build notification-svc (push) Failing after 7m24s
Build backend images / build render-svc (push) Failing after 3m12s
Build backend images / build studio-svc (push) Failing after 43s
feat: AE template scanner + scene editor + AEP bundle pipeline
Scene editor (admin): per-project Scenes / Shared Colors / Color Presets
manager (ProjectScenes) reachable from each project.
AEP bundle pipeline: upload .aep or .zip → stored once per template at
templates/{project_id}/(bundle.zip|template.aep); render claim probes and
returns is_bundle+md5; node-agent extracts the bundle, locates the .aep
(zip-slip guarded), and caches by md5 so repeated renders extract once.
AE template scanner ("read scenes/colours/configs from the AEP"):
- content-svc importer: POST /v1/projects/{id}/scan/{preview,apply} —
review-diff-then-merge into scenes/elements/colours (manual edits kept).
- render-svc Go quick-scan: stdlib RIFX parser extracts comp names+durations
(no AE) → POST /v1/template-scans/{id}/quick.
- render-svc AE scan jobs + node-agent runner: queue → node runs scan.jsx
(reverse of legacy JSXGenerator conventions: frfinal/frshare/frl_/frd_) →
posts ScanResult back. Migration 26_render_scan_jobs.
- admin UI: "اسکن از افترافکت" with quick/full engines + diff-review modal.
Verified: importer preview/apply, Go quick-scan end-to-end (synthetic .aep →
scene imported), bundle extract unit tests, RIFX parser unit tests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
// Package aep is a minimal, stdlib-only reader for After Effects project (.aep)
|
||||
// files. AEP is a RIFX container (big-endian RIFF). This reader does NOT fully
|
||||
// decode the project — it walks the chunk tree to extract composition names and
|
||||
// (best-effort) durations, which is enough for a headless "quick scan" that
|
||||
// scaffolds scenes without After Effects. Full fidelity (layers, colours, fonts)
|
||||
// requires the AE-JSX scanner running on a node.
|
||||
package aep
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Comp is a composition discovered in the project.
|
||||
type Comp struct {
|
||||
Name string
|
||||
DurationSec float64 // 0 when it could not be derived
|
||||
}
|
||||
|
||||
// ParseComps walks a RIFX (.aep) buffer and returns its compositions.
|
||||
//
|
||||
// A composition is an "Item" LIST that contains a "cdta" (composition data)
|
||||
// chunk; its name is the Item's "Utf8" chunk. Folders and footage items lack
|
||||
// "cdta" and are skipped. This rule is robust across AE versions because only
|
||||
// comps carry cdta.
|
||||
func ParseComps(data []byte) ([]Comp, error) {
|
||||
if len(data) < 12 || string(data[0:4]) != "RIFX" {
|
||||
return nil, errors.New("not a RIFX/.aep file")
|
||||
}
|
||||
// data[4:8] = file size (BE), data[8:12] = form type ("Egg!"). Body follows.
|
||||
var comps []Comp
|
||||
seen := map[string]bool{}
|
||||
walk(data[12:], &comps, seen)
|
||||
return comps, nil
|
||||
}
|
||||
|
||||
// walk iterates the chunks in buf (a LIST body or the file root), recursing into
|
||||
// every LIST so nested items inside folders are found.
|
||||
func walk(buf []byte, comps *[]Comp, seen map[string]bool) {
|
||||
off := 0
|
||||
for off+8 <= len(buf) {
|
||||
id := string(buf[off : off+4])
|
||||
size := int(binary.BigEndian.Uint32(buf[off+4 : off+8]))
|
||||
ds := off + 8
|
||||
de := ds + size
|
||||
if size < 0 || de > len(buf) {
|
||||
break
|
||||
}
|
||||
if id == "LIST" && size >= 4 {
|
||||
listType := string(buf[ds : ds+4])
|
||||
body := buf[ds+4 : de]
|
||||
if listType == "Item" {
|
||||
handleItem(body, comps, seen)
|
||||
}
|
||||
walk(body, comps, seen) // recurse (folders hold nested Item LISTs)
|
||||
}
|
||||
adv := 8 + size
|
||||
if size%2 == 1 {
|
||||
adv++ // chunks are word-aligned
|
||||
}
|
||||
off += adv
|
||||
}
|
||||
}
|
||||
|
||||
// handleItem inspects the DIRECT children of an "Item" LIST: a "cdta" marks it as
|
||||
// a composition, the first "Utf8" is its name.
|
||||
func handleItem(body []byte, comps *[]Comp, seen map[string]bool) {
|
||||
var name string
|
||||
var cdta []byte
|
||||
hasCdta := false
|
||||
|
||||
off := 0
|
||||
for off+8 <= len(body) {
|
||||
id := string(body[off : off+4])
|
||||
size := int(binary.BigEndian.Uint32(body[off+4 : off+8]))
|
||||
ds := off + 8
|
||||
de := ds + size
|
||||
if size < 0 || de > len(body) {
|
||||
break
|
||||
}
|
||||
switch id {
|
||||
case "cdta":
|
||||
hasCdta = true
|
||||
cdta = body[ds:de]
|
||||
case "Utf8":
|
||||
if name == "" {
|
||||
name = strings.TrimSpace(strings.TrimRight(string(body[ds:de]), "\x00"))
|
||||
}
|
||||
}
|
||||
adv := 8 + size
|
||||
if size%2 == 1 {
|
||||
adv++
|
||||
}
|
||||
off += adv
|
||||
}
|
||||
|
||||
if hasCdta && name != "" && !seen[name] {
|
||||
seen[name] = true
|
||||
*comps = append(*comps, Comp{Name: name, DurationSec: durationFromCdta(cdta)})
|
||||
}
|
||||
}
|
||||
|
||||
// durationFromCdta makes a best-effort attempt to read the comp duration from the
|
||||
// cdta chunk. The cdta layout varies by AE version; we read the frame-duration /
|
||||
// time-scale pair at well-known offsets and fall back to 0 (unknown) on any doubt.
|
||||
// Returning 0 is safe — the importer treats it as "leave duration unset".
|
||||
func durationFromCdta(cdta []byte) float64 {
|
||||
// cdta encodes time as rational values. Two uint32 BE commonly hold the comp
|
||||
// duration (in frames at the comp's time scale) and the time scale (fps base).
|
||||
// Offsets 0x20 (duration) and 0x24 (scale) are the most consistent across
|
||||
// recent versions; guard heavily and bail to 0 if the numbers look invalid.
|
||||
if len(cdta) < 0x28 {
|
||||
return 0
|
||||
}
|
||||
durFrames := binary.BigEndian.Uint32(cdta[0x20:0x24])
|
||||
scale := binary.BigEndian.Uint32(cdta[0x24:0x28])
|
||||
if scale == 0 || durFrames == 0 || scale > 100000 || durFrames > 100000000 {
|
||||
return 0
|
||||
}
|
||||
sec := float64(durFrames) / float64(scale)
|
||||
if sec <= 0 || sec > 36000 { // > 10h is nonsense → treat as unknown
|
||||
return 0
|
||||
}
|
||||
// round to 2 dp
|
||||
return float64(int(sec*100+0.5)) / 100
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package aep
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// chunk builds a RIFX chunk: 4-byte id + BE32 size + data (+ pad to even).
|
||||
func chunk(id string, data []byte) []byte {
|
||||
b := new(bytes.Buffer)
|
||||
b.WriteString(id)
|
||||
_ = binary.Write(b, binary.BigEndian, uint32(len(data)))
|
||||
b.Write(data)
|
||||
if len(data)%2 == 1 {
|
||||
b.WriteByte(0)
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// list builds a LIST chunk of the given form type wrapping the body chunks.
|
||||
func list(formType string, body []byte) []byte {
|
||||
return chunk("LIST", append([]byte(formType), body...))
|
||||
}
|
||||
|
||||
func cdtaWithDuration(durFrames, scale uint32) []byte {
|
||||
b := make([]byte, 0x28)
|
||||
binary.BigEndian.PutUint32(b[0x20:0x24], durFrames)
|
||||
binary.BigEndian.PutUint32(b[0x24:0x28], scale)
|
||||
return b
|
||||
}
|
||||
|
||||
func TestParseComps(t *testing.T) {
|
||||
// One composition (has cdta), one footage item (no cdta), inside a folder.
|
||||
comp := list("Item", bytes.Join([][]byte{
|
||||
chunk("cdta", cdtaWithDuration(150, 30)), // 150 frames @ 30 → 5.0s
|
||||
chunk("Utf8", []byte("scene_intro")),
|
||||
}, nil))
|
||||
footage := list("Item", bytes.Join([][]byte{
|
||||
chunk("Utf8", []byte("clip.mp4")),
|
||||
chunk("sspc", make([]byte, 8)),
|
||||
}, nil))
|
||||
folder := list("Item", bytes.Join([][]byte{
|
||||
chunk("Utf8", []byte("My Folder")),
|
||||
comp,
|
||||
footage,
|
||||
}, nil))
|
||||
|
||||
body := bytes.Join([][]byte{folder}, nil)
|
||||
// RIFX header: "RIFX" + size + "Egg!" + body
|
||||
file := new(bytes.Buffer)
|
||||
file.WriteString("RIFX")
|
||||
_ = binary.Write(file, binary.BigEndian, uint32(len(body)+4))
|
||||
file.WriteString("Egg!")
|
||||
file.Write(body)
|
||||
|
||||
comps, err := ParseComps(file.Bytes())
|
||||
if err != nil {
|
||||
t.Fatalf("ParseComps: %v", err)
|
||||
}
|
||||
if len(comps) != 1 {
|
||||
t.Fatalf("expected 1 comp, got %d: %+v", len(comps), comps)
|
||||
}
|
||||
if comps[0].Name != "scene_intro" {
|
||||
t.Errorf("name = %q, want scene_intro", comps[0].Name)
|
||||
}
|
||||
if comps[0].DurationSec != 5.0 {
|
||||
t.Errorf("duration = %v, want 5.0", comps[0].DurationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCompsRejectsNonRifx(t *testing.T) {
|
||||
if _, err := ParseComps([]byte("not an aep file at all")); err == nil {
|
||||
t.Error("expected error for non-RIFX input")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user