Skip to content

fix: normalize track array order on save (#21)#22

Merged
renezander030 merged 1 commit into
masterfrom
fix/track-order-21
Jun 3, 2026
Merged

fix: normalize track array order on save (#21)#22
renezander030 merged 1 commit into
masterfrom
fix/track-order-21

Conversation

@renezander030
Copy link
Copy Markdown
Owner

Fixes #21.

Problem

Tracks are appended to draft.tracks in command-call order. CapCut lays out the timeline from the tracks-array order, not from per-segment render_index, so building a draft by adding content in an arbitrary order produced a scrambled timeline on import.

Fix

saveDraft now normalizes the tracks array into the canonical bottom→top layer order before writing:

video → audio → sticker → effect → filter → text

Order derived from a real CapCut-authored draft ([video, audio, text]). Sort is stable, so multiple tracks of the same type keep their authored order, and unknown types are kept after the known ones.

Verification

  • New test/track-order.test.mjs (canonical order, real-draft order, stability, unknown types).
  • Full suite: 117/117 pass.
  • End-to-end: scrambled a draft to [text, audio, video], ran a real CLI edit → output [video, audio, …, text].

🤖 Generated with Claude Code

Tracks were appended to draft.tracks in command-call order. CapCut lays
out the timeline from the tracks-array order, not from per-segment
render_index, so adding content in an arbitrary order produced a
scrambled timeline on import.

Sort tracks into the canonical bottom->top layer order
(video, audio, sticker, effect, filter, text) in saveDraft, with a
stable tiebreak so same-type tracks keep their authored order. Order
derived from a real CapCut-authored draft ([video, audio, text]).

Adds test/track-order.test.mjs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@renezander030 renezander030 merged commit 987fc69 into master Jun 3, 2026
4 checks passed
@renezander030 renezander030 deleted the fix/track-order-21 branch June 3, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The track order is out of order when the project file is placed in capcut.

1 participant