feat(admin): auto-fill new scene length from the AEP
Build backend images / build content-svc (push) Failing after 2m22s
Build backend images / build file-svc (push) Failing after 1m49s
Build backend images / build gateway (push) Failing after 1m6s
Build backend images / build identity-svc (push) Failing after 59s
Build backend images / build notification-svc (push) Failing after 50s
Build backend images / build render-svc (push) Failing after 54s
Build backend images / build studio-svc (push) Failing after 55s

When adding a scene in the admin scene editor, its duration is now pulled
from the After Effects project automatically (scene key = comp name).

frontend (ProjectScenes):
- the new/edit scene form quick-scans the project .aep for comp names +
  durations and offers a "pick composition" dropdown that fills key, title
  and default duration in one click
- the key field gains a datalist of comp names; typing a key that matches a
  comp auto-fills the length (only when empty, never clobbering a manual value)
- an inline "AEP duration: Ns — insert" hint next to the duration field
- graceful states when no .aep is uploaded / scan fails

render-svc (aep.durationFromCdta): fix the composition-duration offset.
The duration rational lives at cdta offset 44 (numerator) / 48 (time base)
on AE 2024/2026, not 32/36 (previous guess) or 40/44 (boltframe reference,
older builds). Made it version-robust: read the time base from the framerate
dividend (offsets 4/8) and accept whichever offset places the time base right
after the numerator. Verified against a real project — render comp frfinal
parses to 15.02s (matches project_duration_sec 15.00).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-07 22:22:39 +03:30
parent da3f92fbe8
commit 23624f7db9
2 changed files with 147 additions and 22 deletions
+34 -17
View File
@@ -181,27 +181,44 @@ func clean(b []byte) string {
return strings.TrimSpace(strings.TrimRight(string(b), "\x00"))
}
// 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".
// durationFromCdta reads the comp duration (in seconds) from the cdta chunk.
//
// cdta layout (verified empirically against AE 2024/2026 project files):
//
// off 4 u32 framerate divisor
// off 8 u32 framerate dividend == comp time base (ticks/sec)
// off 44 u32 duration numerator (in time-base ticks)
// off 48 u32 duration divisor (== time base)
//
// duration_seconds = numerator / time_base. The duration's byte offset shifts by
// AE version (44 on recent builds, 40 on older ones documented by the boltframe
// reference parser), so rather than hard-code one offset we accept whichever
// places the time base immediately *after* the numerator — that self-selects the
// correct field and rejects garbage. Returns 0 (unknown) on any doubt; the
// importer treats 0 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 {
if len(cdta) < 52 {
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 {
frDivisor := binary.BigEndian.Uint32(cdta[4:8])
timeBase := binary.BigEndian.Uint32(cdta[8:12]) // framerate dividend
if frDivisor == 0 || timeBase == 0 {
return 0
}
sec := float64(durFrames) / float64(scale)
if sec <= 0 || sec > 36000 { // > 10h is nonsense → treat as unknown
return 0
if fps := float64(timeBase) / float64(frDivisor); fps < 1 || fps > 240 {
return 0 // not a comp cdta we recognise
}
// round to 2 dp
return float64(int(sec*100+0.5)) / 100
for _, off := range []int{44, 40} { // recent layout first, then older
num := binary.BigEndian.Uint32(cdta[off : off+4])
div := binary.BigEndian.Uint32(cdta[off+4 : off+8])
if num == 0 || div != timeBase {
continue // divisor must equal the time base to be the duration field
}
sec := float64(num) / float64(timeBase)
if sec <= 0 || sec > 36000 { // > 10h is nonsense
continue
}
return float64(int(sec*100+0.5)) / 100 // round to 2 dp
}
return 0
}