fablecut 1.16.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +295 -6
- package/README.md +45 -10
- package/analyze.js +3 -96
- package/app.js +1254 -25
- package/beats.js +458 -0
- package/captions.js +227 -0
- package/delivery.js +22 -2
- package/encoding-profiles.json +26 -0
- package/export-jobs.js +14 -8
- package/highlights.js +296 -0
- package/index.html +17 -0
- package/mcp-server.js +639 -7
- package/package.json +1 -1
- package/project-ops.js +4 -3
- package/reframe.js +297 -0
- package/server.js +60 -0
- package/silence.js +97 -0
- package/style.css +170 -4
- package/transcribe-worker.js +39 -0
- package/transcribe.js +294 -0
- package/transcripts.js +78 -0
package/CLAUDE.md
CHANGED
|
@@ -44,6 +44,19 @@ Every Claude Code session then has these tools:
|
|
|
44
44
|
See "Look at the footage" below.
|
|
45
45
|
- `fablecut_denoise` — reduce background noise on audio clips (renders a cleaned copy of the
|
|
46
46
|
file and switches the clip's stems to it). See "Audio mix" below.
|
|
47
|
+
- `fablecut_silence` — find the pauses in speech and, with `cut:true`, cut them out
|
|
48
|
+
(extract on the targeted tracks, stems in step). See "Audio mix" below.
|
|
49
|
+
- `fablecut_beats` — find a music clip's tempo, beat and drop; mark the beats, snap the
|
|
50
|
+
cuts to them, or re-cut a track's clips on the beat. See "Audio mix" below.
|
|
51
|
+
- `fablecut_reframe` — reframe for another shape (9:16, 1:1, 4:5): a copy of the sequence
|
|
52
|
+
on that canvas whose shots follow the subject. See "Sequences" below.
|
|
53
|
+
- `fablecut_highlights` — the best moments of long footage cut into a short edit, in a new
|
|
54
|
+
sequence. See "Sequences" below.
|
|
55
|
+
- `fablecut_transcribe` — turn speech into words with times (Whisper, in the browser),
|
|
56
|
+
read them on the timeline, find a phrase and cut it out. See "Transcripts and
|
|
57
|
+
text-based editing" below.
|
|
58
|
+
- `fablecut_captions` — caption clips from the transcript, timed word by word (subtitle,
|
|
59
|
+
karaoke, highlight, word pop); export or import SRT / WebVTT. See "Captions" below.
|
|
47
60
|
- `fablecut_export` — render the timeline to a file in `exports/` with the editor's own
|
|
48
61
|
Fast export (open tab, or headless Chrome / Edge). See "Export" below.
|
|
49
62
|
- `fablecut_scopes` — measure the graded picture at a moment (levels, clipping, colour
|
|
@@ -372,6 +385,7 @@ Examples in `library/svg/`: `sparkles.svg` (loop), `lower-third.svg`,
|
|
|
372
385
|
| `fit` | "contain" | contain · cover (fill canvas, crop overflow) · stretch · none (native px) |
|
|
373
386
|
| `cropL` `cropR` `cropT` `cropB` | 0 | % of the source trimmed off each edge |
|
|
374
387
|
| `cornerRadius` | 0 | px, rounded corners — the PiP look |
|
|
388
|
+
| `reframe` | — | set by Reframe (`"follow"` or `"centre"`): the clip's `fit` and position are Reframe's own, so running it again replaces them (see "Sequences") |
|
|
375
389
|
| `flipH`, `flipV` | false | mirror |
|
|
376
390
|
|
|
377
391
|
**Filter / color** (video/image/svg):
|
|
@@ -435,8 +449,11 @@ These are quick looks. For real grading use `props.grade` (see "Color" below).
|
|
|
435
449
|
| `glowColor` | "" | glow color ("" = use the text color) |
|
|
436
450
|
| `strokeWidth` `strokeColor` | 0, "#000" | text outline |
|
|
437
451
|
| `bgColor` `bgOpacity` | "#000", 0 | rounded pill behind each line |
|
|
438
|
-
| `textAnim` | "none" | typewriter · word-pop · word-slide · karaoke · **letter-pop** (per-character entrance; Arabic/Indic auto-fallback to per-word clusters so joined letters shape correctly) · **wave** (looping per-character ride; same shaping fallback) · **bounce** (looping per-word hop) · **shake** (looping jitter) · **clip-reveal** (wipe-mask sweep, per line) · **zoom-in** (scale + opacity settle) · **font-cut** (rhythmically swaps typeface, then settles — see `fontCutSet`) · **rise-mask** (line rises from behind its baseline, lower-third reveal) |
|
|
452
|
+
| `textAnim` | "none" | typewriter · word-pop · word-slide · karaoke · **highlight** (every word shown; the one being said in `highlightColor`) · **letter-pop** (per-character entrance; Arabic/Indic auto-fallback to per-word clusters so joined letters shape correctly) · **wave** (looping per-character ride; same shaping fallback) · **bounce** (looping per-word hop) · **shake** (looping jitter) · **clip-reveal** (wipe-mask sweep, per line) · **zoom-in** (scale + opacity settle) · **font-cut** (rhythmically swaps typeface, then settles — see `fontCutSet`) · **rise-mask** (line rises from behind its baseline, lower-third reveal) |
|
|
439
453
|
| `wordRate` | 0.15 | seconds per word (typewriter: /4, letter-pop: /3 per character); also staggers `clip-reveal`/`zoom-in`/`rise-mask` per line |
|
|
454
|
+
| `wordTimes` | — | `[[start, end], …]`, one pair per word (seconds from the clip's start): word-pop, word-slide, karaoke and highlight follow these instead of `wordRate` — a caption timed to speech. If the text is edited to another number of words they are spread over the clip. See "Captions" |
|
|
455
|
+
| `highlightColor` | "#ffd166" | the colour of the word being said in `highlight` |
|
|
456
|
+
| `caption` · `captionStyle` | — | set on caption clips (see "Captions"): how they are found, replaced and exported |
|
|
440
457
|
| `textPath` | — | set the title along a path: one shape item (`path`, `line`, `ellipse`, `rect`, `polygon`, `star`) whose outline is the baseline; more lines follow on parallel curves below it. See "Motion paths, motion blur and text on a path" |
|
|
441
458
|
| `pathOffset` · `pathAlign` | 0 · "start" | where along the path the text sits (% of its length, keyframable, wraps on closed paths) · which end of the text sits there: start · center · end |
|
|
442
459
|
| `fontCutSet` | (curated) | array of font family names cycled by `font-cut`, e.g. `["Anton","Bebas Neue","Archivo Black","Oswald"]`; each is auto-loaded |
|
|
@@ -600,6 +617,57 @@ edits the key under the playhead. Agents:
|
|
|
600
617
|
on the music: ramp down `attack` s before speech, hold, back up over
|
|
601
618
|
`release` s. It replaces earlier ducking; `amount:0` clears it. Same as the
|
|
602
619
|
inspector's **Auto-duck** section or the clip menu's *Auto-duck under other tracks*.
|
|
620
|
+
- **Silence** — `fablecut_silence {clipIds, threshold?:-40, minSilence?:0.5, padding?:0.15, cut?, tracks?, force?}`
|
|
621
|
+
listens to the speech clips (a video brings its linked stems; each measured after
|
|
622
|
+
its channel routing, gain and volume) and finds every stretch where none of them
|
|
623
|
+
is above `threshold` dBFS for at least `minSilence` seconds. It keeps `padding`
|
|
624
|
+
seconds of quiet after the phrase before and before the phrase after, so words
|
|
625
|
+
aren't clipped; a clip's own start and end are cut to the first and last word.
|
|
626
|
+
Cuts land on whole frames, and the gaps *between* clips are left alone. Without
|
|
627
|
+
`cut` it only reports the spans (timeline seconds). With `cut:true` each one is
|
|
628
|
+
removed with an `extract` on the targeted tracks (`tracks` picks others), last
|
|
629
|
+
first, in one revision: later material moves up, linked stems stay in step, and
|
|
630
|
+
locked tracks and clips stay where they are — **lock the music bed first** if it
|
|
631
|
+
should keep running under the tightened edit. `force:true` cuts through locked
|
|
632
|
+
material too, so pass it only when the user asked. Only time that was actually
|
|
633
|
+
heard is cut: a clip with no audio stream (or disabled) is left alone, and so is
|
|
634
|
+
one with a speed ramp (`keyframes.speed`) — its sound doesn't sit on the timeline
|
|
635
|
+
at one speed. A version
|
|
636
|
+
of the project as it was is kept before the cut; if that fails the reply says
|
|
637
|
+
so in a warning, and then there is no version to go back to. Raise `threshold`
|
|
638
|
+
toward −30 in a noisy room; lower `minSilence` for a tighter, jump-cut feel. In
|
|
639
|
+
the editor: the Inspector's **Silence** section on an audio or video clip (or
|
|
640
|
+
right-click → **Find silences**) — **Find** marks the silences on the timeline
|
|
641
|
+
as amber bands, **Cut N** extracts them (one undo step), **Clear** removes the
|
|
642
|
+
marks. The marks drop when the timeline, a clip's file, speed or level, or the
|
|
643
|
+
frame rate changes.
|
|
644
|
+
- **Beats** — `fablecut_beats {clipId, markers?, snap?, retime?, every?, force?}`
|
|
645
|
+
listens to a music clip (an audio clip, or a video's sound) and finds its tempo
|
|
646
|
+
(BPM), a **steady beat grid** — the tempo's period, phased and fitted to the
|
|
647
|
+
hits, so it doesn't drift over a song — and the drop, all in timeline seconds
|
|
648
|
+
through the clip's in point and speed. On its own it only reports. Then, in one
|
|
649
|
+
revision: `markers:true` puts a cyan marker on every beat (other markers stay, and a
|
|
650
|
+
beat that already has one keeps it);
|
|
651
|
+
`snap:true` (or `{tracks, maxShift}`) rolls each cut on the targeted video tracks
|
|
652
|
+
to the nearest beat within half a beat — a roll, so nothing else moves and
|
|
653
|
+
linked stems follow; a cut whose clips have no spare footage to reach the beat
|
|
654
|
+
stays where it is, and the reply says how many; `retime:{track?, every?, from?}`
|
|
655
|
+
lays a track's clips (default the lowest video track with clips) back to back
|
|
656
|
+
on the beat, `every` beats each (1, 2, 4, 8 or 16; default 2), from the first
|
|
657
|
+
beat at or after `from` (default the music's start), in their order — a clip
|
|
658
|
+
whose footage runs out gets fewer beats, clips past the music keep their
|
|
659
|
+
length, and one with less than a beat of footage refuses the whole re-cut.
|
|
660
|
+
Locked clips are left alone by snap and refuse retime, unless `force:true`
|
|
661
|
+
(only when the user asked). A version is kept before snap or retime; if saving it
|
|
662
|
+
fails, the edit still goes ahead and the reply says so in a warning. A re-cut clip
|
|
663
|
+
that gets shorter loses the keyframes past its new end, and its transitions are
|
|
664
|
+
kept no longer than the clip, as with a trim. The music clip itself (and its linked
|
|
665
|
+
stems) is never re-cut, even when it sits on the track being re-cut. Cuts land
|
|
666
|
+
on whole frames. A clip with a speed ramp is refused: its music doesn't keep
|
|
667
|
+
time on the timeline. In the editor: the Inspector's **Beats** section on an
|
|
668
|
+
audio or video clip — **Find beats** shows the beat as ticks across the
|
|
669
|
+
timeline and the BPM and drop below; then **Mark**, **Snap cuts**, and
|
|
670
|
+
**Re-cut** a track every N beats (each one undo step).
|
|
603
671
|
- In the editor, each audio clip shows its **volume line** (yellow; dashed =
|
|
604
672
|
after ducking): drag it to change the level, Ctrl/Cmd-click to add a keyframe,
|
|
605
673
|
drag a point to move it, Alt-click or double-click to remove one. The corner
|
|
@@ -609,6 +677,132 @@ edits the key under the playhead. Agents:
|
|
|
609
677
|
balance whole lanes (dialogue against the music bed), and a **bus** when
|
|
610
678
|
several lanes need the same processing or one fader.
|
|
611
679
|
|
|
680
|
+
### Transcripts and text-based editing
|
|
681
|
+
|
|
682
|
+
FableCut turns the speech in a clip into **words with times**, so an edit can be
|
|
683
|
+
read, searched and cut like text. Transcription runs **in the browser**: Whisper
|
|
684
|
+
(OpenAI's speech model, through transformers.js) in a background worker of the
|
|
685
|
+
editor tab. The library and the model are fetched from a CDN the first time and
|
|
686
|
+
kept by the browser after that; the audio never leaves the machine.
|
|
687
|
+
|
|
688
|
+
| model | download | |
|
|
689
|
+
|---|---|---|
|
|
690
|
+
| `base` (default) | 77 MB | quick: about 15 s per minute of speech on a fast desktop |
|
|
691
|
+
| `small` | 250 MB | often more accurate (accents, noisy rooms, numbers); about twice as slow |
|
|
692
|
+
|
|
693
|
+
Whisper detects the language by itself; give it one (`en`, `es`, `hi`, `ja`, … any
|
|
694
|
+
Whisper code) when a clip is short or mixes languages. Long files are split at
|
|
695
|
+
their quietest moments into pieces of at most 28 s, and stretches of silence are
|
|
696
|
+
skipped (Whisper invents words in silence).
|
|
697
|
+
|
|
698
|
+
**One transcript per file**, kept by the server in `analysis/transcripts/`:
|
|
699
|
+
`{v, src, model, language, duration, created, words:[[text, start, end], …]}`,
|
|
700
|
+
times in seconds of the file. Like a proxy it belongs to the file's size and
|
|
701
|
+
modification time, so a replaced or re-rendered file has none until it is
|
|
702
|
+
transcribed again. It is not stored in `project.json`, so it never bloats the
|
|
703
|
+
timeline, and every clip and sequence that uses the file reads the same one.
|
|
704
|
+
|
|
705
|
+
**On the timeline** a clip shows the words its window of the file holds, placed
|
|
706
|
+
through its `in` point and `speed` (a word counts when its middle is inside the
|
|
707
|
+
clip). A clip with a speed ramp is left out, and so are disabled clips and pictures
|
|
708
|
+
whose sound is off.
|
|
709
|
+
|
|
710
|
+
**Cutting words** extracts on the targeted tracks, from just before the first word
|
|
711
|
+
to just before the word after the last one: the pause after the cut goes too, the
|
|
712
|
+
pause before it stays. Cuts land on whole frames, never in a neighbouring word or
|
|
713
|
+
past the clip. Several cuts go last first, as one undo step (one revision for an
|
|
714
|
+
agent): later material moves up, linked stems stay in step, and locked clips stay
|
|
715
|
+
put — **lock the music bed first** if it should keep running under the tightened
|
|
716
|
+
edit. Find matches whole words and ignores case, accents, punctuation and spacing:
|
|
717
|
+
"ai powered" finds "A.I.-powered", and "cat" doesn't find "category".
|
|
718
|
+
|
|
719
|
+
In the editor, the **Transcript** tab beside the Inspector:
|
|
720
|
+
|
|
721
|
+
- **Transcribe** works on the selected clips' files, else on every file on the
|
|
722
|
+
timeline that has no transcript yet. The model and the language are beside it.
|
|
723
|
+
Progress shows below (the first time, the model download), with **Cancel**.
|
|
724
|
+
- The timeline's words, in paragraphs with timecodes. Click a word to go there;
|
|
725
|
+
the word under the playhead is underlined and followed while playing. ⇧-click or
|
|
726
|
+
drag to select a run of words, then press **Delete** (or **Cut**) to extract it.
|
|
727
|
+
- **Find words** marks every match, Enter steps through them, and **Cut N**
|
|
728
|
+
extracts them all. **Copy** copies the text with its timecodes.
|
|
729
|
+
|
|
730
|
+
**Agents** use `fablecut_transcribe`. It transcribes in an open editor tab, else in
|
|
731
|
+
headless Chrome / Edge, whose profile is kept in `analysis/browser-profile/` so the
|
|
732
|
+
model downloads once:
|
|
733
|
+
|
|
734
|
+
- `{}` transcribes every clip with sound that has no transcript yet, then returns
|
|
735
|
+
the timeline's words as timed lines: `[0:12.08] Open the demo, nothing to install.`
|
|
736
|
+
`clipIds` limits it to some clips; `from` / `to` limit the time (the reply stops
|
|
737
|
+
at 300 lines); `mediaIds` reads whole files in file seconds instead.
|
|
738
|
+
- `model:"small"`, `language:"es"`, and `again:true` (transcribe again, with another
|
|
739
|
+
model or language).
|
|
740
|
+
- `find:"phrase"` (or a list) reports each place it is said, with its span, the words
|
|
741
|
+
around it and how much cutting them would remove; `cut:true` extracts them
|
|
742
|
+
(`tracks` and `force` as for `fablecut_silence`). A version of the project is kept
|
|
743
|
+
before the cut.
|
|
744
|
+
|
|
745
|
+
Whisper writes clean text: it often leaves out fillers ("um", "uh") and false
|
|
746
|
+
starts, so find those by ear (`fablecut_silence` for the pauses), not by text. Word
|
|
747
|
+
times are good to about a tenth of a second; listen to a cut that matters, or
|
|
748
|
+
check it with `fablecut_frame`.
|
|
749
|
+
|
|
750
|
+
### Captions
|
|
751
|
+
|
|
752
|
+
Captions are made from a transcript (see "Transcripts and text-based editing"):
|
|
753
|
+
the timeline's words are grouped into captions, and each caption is an ordinary
|
|
754
|
+
**text clip** with `wordTimes` (each word's start and end), so its animation follows
|
|
755
|
+
the speech word by word, and `caption: true`, so captions can be found, replaced
|
|
756
|
+
and exported as a group. Because they are text clips they render the same way in
|
|
757
|
+
preview and export (burned into the picture), and the Inspector restyles them like
|
|
758
|
+
any title.
|
|
759
|
+
|
|
760
|
+
| style | look |
|
|
761
|
+
|---|---|
|
|
762
|
+
| `subtitle` (default) | plain text on a dark bar, low on the frame, up to two lines |
|
|
763
|
+
| `karaoke` | bold outlined text; each word lights up as it is said |
|
|
764
|
+
| `highlight` | big uppercase outlined words, the one being said in a colour (`highlightColor`) — the short-video look; up to five words |
|
|
765
|
+
| `pop` | one to three big words at a time, each popping in as it is said |
|
|
766
|
+
|
|
767
|
+
A new caption starts at a pause of 0.6 s or more, after a sentence, after a comma
|
|
768
|
+
once it has three words, or when it would run too long (lines, words or seconds).
|
|
769
|
+
Lines are as long as fit the canvas at the style's size: sizes follow the
|
|
770
|
+
canvas's shorter side, so a 9:16 reel gets narrower captions than a 16:9 video.
|
|
771
|
+
Each caption stays about a quarter of a second after its last word, never into
|
|
772
|
+
the next one, and starts and ends on whole frames.
|
|
773
|
+
|
|
774
|
+
They go on the video lane captions are already on; otherwise on the top video
|
|
775
|
+
lane when nothing is there while they run, else on a new lane above it. Making
|
|
776
|
+
captions again **replaces** the ones there. Make them **after the cutting is done**:
|
|
777
|
+
a cut through a caption shortens it but doesn't re-time its words, so make them
|
|
778
|
+
again after you change the edit. The editor says so for a moment whenever an edit shortens a caption.
|
|
779
|
+
|
|
780
|
+
In the editor, the **Captions** row of the **Transcript** tab: pick a style, then
|
|
781
|
+
**Add captions** (one undo step). **SRT** and **VTT** download the timeline's
|
|
782
|
+
captions as a subtitle file; **Import…** places the captions of an SRT or WebVTT
|
|
783
|
+
file instead, re-broken to the style's line length, with their words spread over
|
|
784
|
+
each caption. Select a caption to restyle it in the Inspector: the **Highlight**
|
|
785
|
+
colour sits under **Animation**, and a note says its words follow the speech.
|
|
786
|
+
|
|
787
|
+
**Agents** use `fablecut_captions`:
|
|
788
|
+
|
|
789
|
+
- `{}` or `{style:"highlight"}` makes captions from every clip with sound
|
|
790
|
+
(transcribing what has no transcript yet, as `fablecut_transcribe` does), and
|
|
791
|
+
answers with where they went and the first few. `clipIds`, `from` / `to` limit
|
|
792
|
+
it; `lines`, `words` and `size` (a scale on the style's size) adjust it;
|
|
793
|
+
`track` picks the lane; `replace:false` keeps the captions already there.
|
|
794
|
+
- `{export:"srt"}` or `{export:"vtt"}` writes the captions that show (not disabled,
|
|
795
|
+
not on a disabled track) to `exports/<project name>.srt` or `.vtt`, adding a number
|
|
796
|
+
when that name is taken (`<project name> 2.srt`), and returns the path: use that one.
|
|
797
|
+
- `{import:"<path to .srt or .vtt>"}` places a file's captions (the file's text
|
|
798
|
+
works too).
|
|
799
|
+
- `{remove:true}` deletes every caption clip. Locked captions are left alone and
|
|
800
|
+
refuse the call unless `force:true`.
|
|
801
|
+
- Check one with `fablecut_frame {time}` while a word is being said. Restyle them
|
|
802
|
+
all with `updateClip` (e.g. `props:{highlightColor:"#22d3ee", y:500}`) on each
|
|
803
|
+
caption id from the compact view, which lists a caption as
|
|
804
|
+
`[5 words timed to speech]` instead of its times.
|
|
805
|
+
|
|
612
806
|
### Color
|
|
613
807
|
|
|
614
808
|
A clip's color grade lives in `props.grade` on any video, image, svg or
|
|
@@ -1584,7 +1778,9 @@ list short without deleting anything.
|
|
|
1584
1778
|
|
|
1585
1779
|
### Versions
|
|
1586
1780
|
|
|
1587
|
-
Every edit is saved as it happens, and undo covers the session.
|
|
1781
|
+
Every edit is saved as it happens, and undo covers the session. An edit that
|
|
1782
|
+
reaches the open editor from outside (an agent, another tab) is one undo step of
|
|
1783
|
+
its own there: Ctrl+Z takes it back first, then the user's own edits. **Versions** are
|
|
1588
1784
|
what you come back to later: full copies of a project, kept beside it, that are
|
|
1589
1785
|
never overwritten. Restoring one is not destructive either — what is there is
|
|
1590
1786
|
saved as a version first, so a restore can be undone by restoring that.
|
|
@@ -1712,10 +1908,68 @@ sequence.
|
|
|
1712
1908
|
sequence's changes on its own, sequences added and removed, and which one
|
|
1713
1909
|
was open.
|
|
1714
1910
|
|
|
1715
|
-
|
|
1911
|
+
**Reframe** — `fablecut_reframe {aspect?:"9:16"|"1:1"|"4:5"|"16:9"|"4:3"|"2:3", name?, clipIds?, follow?, smooth?, force?}`
|
|
1912
|
+
makes a copy of the open sequence on that canvas shape and opens it (the
|
|
1913
|
+
project's shorter side kept: 1920×1080 → 1080×1920 for 9:16, 1080×1080 for
|
|
1914
|
+
1:1), so the original cut stays as it was; without `aspect` it reframes the
|
|
1915
|
+
open sequence on its own canvas. Each full-frame shot — a video or still that
|
|
1916
|
+
isn't moved, scaled, cropped or keyed by hand — gets `fit:"cover"` and an `x`
|
|
1917
|
+
(or `y`) that keeps its subject in view. Frames are sampled 5 times a second at
|
|
1918
|
+
96 px; the subject is where motion (against the shot's own movement, so a pan
|
|
1919
|
+
or a flicker doesn't count), detail and colour gather, pulled gently toward
|
|
1920
|
+
the centre. A virtual camera operator then holds still while the subject
|
|
1921
|
+
stays inside a dead zone and eases after it no faster than a pan speed, and
|
|
1922
|
+
the path becomes ordinary keyframes (thinned to within ~2 px), or one steady
|
|
1923
|
+
position. Shots with no clear subject are centred. Titles, picture-in-picture,
|
|
1924
|
+
clips placed or animated by hand and locked clips (unless `force:true`) are
|
|
1925
|
+
left alone and listed in the reply — check them on the new canvas with
|
|
1926
|
+
`fablecut_frame {time}`. `follow:false` only fits and centres; `smooth` 0…1
|
|
1927
|
+
(default 0.5) holds longer and pans slower as it rises. `props.reframe` marks
|
|
1928
|
+
what Reframe did, so running it again replaces its own keys. A version is kept
|
|
1929
|
+
first. In the editor: **New sequence…** with a copy of the open sequence on
|
|
1930
|
+
another shape has **Follow the subject in each shot**; the Inspector's
|
|
1931
|
+
**Reframe** section on a video or picture of another shape than the canvas
|
|
1932
|
+
has **Follow subject**, **Centre** and Lively / Balanced / Steady (the selected
|
|
1933
|
+
clips, one undo step, with Cancel).
|
|
1934
|
+
|
|
1935
|
+
**Highlights** — `fablecut_highlights {duration?, shot?, clipIds?, mediaIds?, name?, aspect?}`
|
|
1936
|
+
finds the best moments of long footage and cuts them into a short edit: a new
|
|
1937
|
+
sequence (`Highlights 30 s`, or `name`), opened, so the timeline it came from
|
|
1938
|
+
stays as it was. It reads the video clips on the open timeline (`clipIds`
|
|
1939
|
+
limits them; `mediaIds` reads whole files instead), up to an hour of footage
|
|
1940
|
+
at a time: frames twice a second at 64 px, and the sound. Every half second is
|
|
1941
|
+
scored for movement, sound louder than the 20 s around it (a cheer, a laugh, a
|
|
1942
|
+
hit), its overall level, and a clear picture; black frames and flat colour
|
|
1943
|
+
count for little. Cuts already in the footage are found, and a moment never
|
|
1944
|
+
crosses one. It then takes the best moments of `shot` seconds (default
|
|
1945
|
+
`duration` / 8, kept within 1.5–4 s), apart in the same footage (by half a
|
|
1946
|
+
moment, at least a second) and spread over its shots, until the edit is `duration` seconds
|
|
1947
|
+
(default 30; 5…600), trims the last ones to fit exactly, and nudges each end up
|
|
1948
|
+
to 0.3 s to the quietest point near it, so no word or hit is cut through. The
|
|
1949
|
+
moments go back to back on V1 in story order, each a clip of its source with
|
|
1950
|
+
its props (a reframed clip's framing isn't carried over) and its linked sound
|
|
1951
|
+
clips beside it (their own tracks, linked again); their keyframes aren't
|
|
1952
|
+
carried over. A moment from a whole file (`mediaIds`) is one video clip that
|
|
1953
|
+
plays its own sound, with no separate audio clips. A clip played faster or
|
|
1954
|
+
slower counts by its length on the timeline: `duration` and `shot` are always
|
|
1955
|
+
seconds of the edit. In the editor (and Studio) the sound of a file longer than
|
|
1956
|
+
30 minutes isn't read, so as not to decode it whole in the browser; its picture
|
|
1957
|
+
decides. Disabled clips and clips with a speed ramp are not read. `aspect`
|
|
1958
|
+
makes the new sequence 9:16, 1:1 or 4:5: the shots are then letterboxed, and
|
|
1959
|
+
`fablecut_reframe {}` fits them and follows the subject. The reply lists each
|
|
1960
|
+
moment (its source, times, length, why it was picked and its score). A version
|
|
1961
|
+
is kept first. In the editor: the sequence menu's **Highlights…** (15, 30, 60 or
|
|
1962
|
+
90 s; a canvas, and **Follow the subject in each shot** on another shape)
|
|
1963
|
+
reads the selected video clips, else every video clip on the timeline, with
|
|
1964
|
+
progress and **Cancel**.
|
|
1965
|
+
|
|
1966
|
+
Recipes: **vertical cut of a finished edit** — `fablecut_reframe {aspect:"9:16"}`,
|
|
1967
|
+
then check the titles with `fablecut_frame`; by hand, `addSequence {name:"Reel 9:16",
|
|
1716
1968
|
from:"open", width:1080, height:1920}`, then `inSequence` ops to re-position
|
|
1717
1969
|
or re-scale the shots and `setProject {delivery:"instagram-reels"}` in it;
|
|
1718
|
-
**
|
|
1970
|
+
**reel from a long video** — `fablecut_highlights {duration:30, aspect:"9:16"}`,
|
|
1971
|
+
then `fablecut_reframe {}`, music on an audio track and `fablecut_beats {clipId:<the music>, retime:{every:2}}`,
|
|
1972
|
+
then captions; **cut-downs** — duplicate the edit as "30 s" and "15 s" and tighten each with
|
|
1719
1973
|
the trim ops inside `inSequence`; **selects reel** — an empty sequence the
|
|
1720
1974
|
user drops favourite takes on, cut into the edit from the Source monitor.
|
|
1721
1975
|
|
|
@@ -1962,6 +2216,13 @@ obvious cuts were missed, raise it if motion is being misread as cuts.
|
|
|
1962
2216
|
port) in `media.src`: canvas CORS would taint the compositor and Fast /
|
|
1963
2217
|
WebCodecs export cannot JPEG-encode. Import into `./media` so `src` is
|
|
1964
2218
|
`/media/…`, or serve the remote with `Access-Control-Allow-Origin`.
|
|
2219
|
+
- `GET /api/transcript?src=/media/x.mp4` → `{transcript}` (`null` when the file has none yet; 404 when the
|
|
2220
|
+
file is missing) · `POST /api/transcript?src=` (a transcript document) → `{src, words}` ·
|
|
2221
|
+
`POST /api/transcript/status {srcs}` → `{status:{src: {words, language, model, duration, created} | false | null}}` ·
|
|
2222
|
+
`POST /api/transcript/delete {src}` → `{deleted}`. SSE event `transcript` (`{src}`) after each save or delete.
|
|
2223
|
+
`POST /api/transcribe/request {transcribe:{srcs, model?, language?, again?}, where?}` queues a transcription
|
|
2224
|
+
on the export-job queue (poll `GET /api/export/job?id=`); the tab saves each transcript, and the job's
|
|
2225
|
+
`result` lists `done`, `skipped` and `failed`. See "Transcripts and text-based editing".
|
|
1965
2226
|
- `POST /api/denoise` — body `{src:"/media/…", amount:"light"|"medium"|"strong"}`: writes a
|
|
1966
2227
|
noise-reduced FLAC of the whole file into `./media/` (reused if it exists) and returns
|
|
1967
2228
|
`{src, name, duration, channels}`. Does not touch `project.json` (see "Audio mix").
|
|
@@ -2063,6 +2324,33 @@ so all takes sit at one loudness, then keep the music on its own lane and pull
|
|
|
2063
2324
|
that lane down: `{op:"setTrack", id:"A3", set:{gain:-14}}`. Then dip it under the
|
|
2064
2325
|
voice: `fablecut_auto_duck {clipIds:[<music clip>], under:["A1"], amount:-10}`.
|
|
2065
2326
|
|
|
2327
|
+
**Cut a montage to the music**: put the shots on V1 in the order you want (rough
|
|
2328
|
+
lengths are fine) and the music on an audio lane, then
|
|
2329
|
+
`fablecut_beats {clipId:<the music>, retime:{every:2}}` — each shot gets two beats
|
|
2330
|
+
where its footage allows (fewer when it runs out; clips past the music keep their
|
|
2331
|
+
length; one with less than a beat of footage refuses the re-cut), the cuts land on the beat. `every:1` for a fast reel, `4` for a calm one;
|
|
2332
|
+
re-cut the part after the drop separately with `retime:{from:<the drop>, every:1}`.
|
|
2333
|
+
For an edit whose cuts are already chosen, `snap:true` just nudges each one onto
|
|
2334
|
+
the nearest beat (cuts on untargeted tracks, beside locked clips, or without spare
|
|
2335
|
+
footage to reach it stay where they are; the reply counts them). Check a cut with `fablecut_frame` before exporting.
|
|
2336
|
+
|
|
2337
|
+
**Tighten a talking-head take**: lock the music lane (`setProject {lockedTracks:["A3"]}`),
|
|
2338
|
+
then `fablecut_silence {clipIds:[<the take>]}` to see the pauses (it does the
|
|
2339
|
+
listening; `fablecut_frame` only shows the picture, handy to check a cut won't land
|
|
2340
|
+
mid-gesture), and `fablecut_silence {clipIds:[<the take>], cut:true}`. Add
|
|
2341
|
+
`{op:"crossfade", ids:[…]}` on the new audio cuts if a breath clicks.
|
|
2342
|
+
|
|
2343
|
+
**Cut an interview down by text**: lock the music lane, `fablecut_transcribe {clipIds:[<the interview>]}`
|
|
2344
|
+
to read what was said (name the speech clips, or the music bed is transcribed too), decide what stays, then
|
|
2345
|
+
`fablecut_transcribe {clipIds:[<the interview>], find:["the sentence to drop", "and this one"], cut:true}`.
|
|
2346
|
+
Then `fablecut_silence {clipIds:[…], cut:true}` for the pauses that are left.
|
|
2347
|
+
|
|
2348
|
+
**Caption a talking-head reel**: finish the cut first, then
|
|
2349
|
+
`fablecut_captions {style:"highlight", clipIds:[<the talking-head clips>]}` (name the speech
|
|
2350
|
+
clips, or a music bed with vocals gets captioned too), `fablecut_frame {time:<mid-sentence>}` to
|
|
2351
|
+
check the size and placement, and `fablecut_captions {export:"srt"}` for the
|
|
2352
|
+
platform's own subtitle upload.
|
|
2353
|
+
|
|
2066
2354
|
**Center a mono stem**: linked or standalone audio clip with `props.pan: 0` (inspector **Pan** slider, −1…+1). Stereo video stems default to L `−1` / R `+1`; set A1 to `0` to center that channel in the mix.
|
|
2067
2355
|
|
|
2068
2356
|
**Cinematic grade**: `props.filterPreset: "teal-orange"` (tweak with
|
|
@@ -2401,8 +2689,9 @@ ffmpeg -y -f image2pipe -framerate <fps> -i - [-i audio.wav] <jpeg-color> <args
|
|
|
2401
2689
|
|
|
2402
2690
|
- **There is no allow-list.** Any codec, filter, container or flag your local ffmpeg
|
|
2403
2691
|
supports works — ProRes, DNxHD, NVENC/QSV/VideoToolbox, VP9/AV1, 10-bit, HDR tags.
|
|
2404
|
-
See the shipped `prores422`, `broadcast1080i50`, `nvenc-h264
|
|
2405
|
-
profiles (the NVENC ones need an
|
|
2692
|
+
See the shipped `prores422`, `broadcast1080i50`, `nvenc-h264`, `nvenc-hevc`,
|
|
2693
|
+
`videotoolbox-h264` and `videotoolbox-hevc` profiles (the NVENC ones need an
|
|
2694
|
+
NVIDIA GPU; VideoToolbox requires macOS / Apple Silicon).
|
|
2406
2695
|
- **Args are validated by ffmpeg itself**, not by a schema: when an export starts the
|
|
2407
2696
|
server dry-runs the profile against a 0.1 s synthetic input (`lavfi`). A typo or an
|
|
2408
2697
|
encoder your build lacks is rejected up front with ffmpeg's own message, instead of
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
</div>
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
[](https://fablecut.space/showcase/fablecut-studio-demo.mp4)
|
|
24
24
|
|
|
25
25
|
FableCut is a Premiere-style non-linear video editor that runs entirely in your
|
|
26
26
|
browser — and exposes its whole timeline as one JSON document. Edit it by hand,
|
|
@@ -32,6 +32,14 @@ Zero npm dependencies. One `node server.js`. That's it.
|
|
|
32
32
|
|
|
33
33
|

|
|
34
34
|
|
|
35
|
+
## Sponsors
|
|
36
|
+
|
|
37
|
+
<a href="https://fluxionai.space/register?source=github&campaign=github-sidrune-fablecut&promo=SDRFABLECUT" target="_blank" rel="noopener noreferrer sponsored">
|
|
38
|
+
<img src="docs/sponsors/sidrune-ai-banner.png" alt="Sidrune AI — one API for GPT, Claude and other leading AI models" width="640">
|
|
39
|
+
</a>
|
|
40
|
+
|
|
41
|
+
**[Sidrune AI](https://fluxionai.space/register?source=github&campaign=github-sidrune-fablecut&promo=SDRFABLECUT)** — One API for GPT, Claude, and other leading AI models. Sign up and get $3 in API credit.
|
|
42
|
+
|
|
35
43
|
## Why it's interesting
|
|
36
44
|
|
|
37
45
|
Most "AI video" tools hide the edit behind an API. FableCut flips that: the
|
|
@@ -41,6 +49,15 @@ can edit video, and the open browser UI hot-reloads within ~150 ms via
|
|
|
41
49
|
server-sent events. A human and an agent can work on the same timeline at the
|
|
42
50
|
same time.
|
|
43
51
|
|
|
52
|
+
**Taking back what the agent did.** Every agent edit is one undo step of its
|
|
53
|
+
own: Ctrl+Z takes back the agent's last change first (and says so), then
|
|
54
|
+
goes on to yours, so the two never get mixed. For bigger rollbacks there are
|
|
55
|
+
**Versions**: one is kept when an agent starts editing (again at most every
|
|
56
|
+
10 minutes while it works), before it rewrites the whole project, before every
|
|
57
|
+
big operation (cutting silences, snapping to the beat, reframing), and every
|
|
58
|
+
10 minutes while you edit. Restore one from the Versions panel, or ask the agent
|
|
59
|
+
(`fablecut_versions`), and compare any version with now first.
|
|
60
|
+
|
|
44
61
|
## Features
|
|
45
62
|
|
|
46
63
|
**Editing**
|
|
@@ -119,6 +136,30 @@ same time.
|
|
|
119
136
|
Strong) measures the file's noise floor and renders a cleaned copy with
|
|
120
137
|
ffmpeg; the clip's audio switches to it and **Off** switches back. Agents
|
|
121
138
|
use `fablecut_denoise`.
|
|
139
|
+
- **Reframe** — make a 9:16, 1:1 or 4:5 copy of your edit whose shots follow
|
|
140
|
+
the subject: a virtual camera pans after what matters in each shot and
|
|
141
|
+
writes ordinary position keys you can still edit. From **New sequence…**
|
|
142
|
+
or the Inspector's **Reframe** section; agents use `fablecut_reframe`.
|
|
143
|
+
- **Highlights** — the best moments of long footage (movement, sound, a
|
|
144
|
+
clear picture) cut into a short edit in a new sequence, in story order and
|
|
145
|
+
never across a cut. From the sequence menu's **Highlights…**; agents use
|
|
146
|
+
`fablecut_highlights`.
|
|
147
|
+
- **Silence removal** — the inspector's **Silence** section (or right-click →
|
|
148
|
+
**Find silences**) listens to a take and marks every pause on the timeline;
|
|
149
|
+
**Cut** extracts them all in one undo step, keeping a little quiet beside
|
|
150
|
+
each phrase so words aren't clipped. Agents use `fablecut_silence`.
|
|
151
|
+
- **Beats** — the inspector's **Beats** section finds a music clip's tempo, a
|
|
152
|
+
steady beat grid and the drop, and shows the beat across the timeline. Mark
|
|
153
|
+
the beats, snap every cut onto the nearest one, or re-cut a track so each
|
|
154
|
+
shot lasts 1, 2, 4, 8 or 16 beats. Agents use `fablecut_beats`.
|
|
155
|
+
- **Transcripts and text-based editing** — the **Transcript** tab turns speech
|
|
156
|
+
into words with times, in the browser (Whisper; the model downloads once and
|
|
157
|
+
the audio never leaves your machine). Click a word to go there, select words
|
|
158
|
+
and press Delete to cut them, or find a phrase and cut every time it is said.
|
|
159
|
+
Agents use `fablecut_transcribe` to read an interview, find a line and cut it.
|
|
160
|
+
- **Captions** — one click makes captions from the transcript, timed word by
|
|
161
|
+
word: subtitle, karaoke, a highlighted word or big popping words, sized for
|
|
162
|
+
the canvas. Export or import SRT and WebVTT. Agents use `fablecut_captions`.
|
|
122
163
|
- **Project bin folders** — tree view with expand/collapse; drag media or folders to nest; right-click the **Project** tab → New folder; drop files onto a folder to import into it
|
|
123
164
|
- **Media management** — each file's frame rate, codecs, audio channels and size (ffprobe); search by name, codec, resolution or `#tag`; filter by favorites, used / unused, kind, tag or collection; sort by any detail or by times used; a list view with metadata columns; favorites, tags and collections; **Find timeline instances** and **Reveal in project**; offline files flagged with a "Media offline" slate, **Relink…** (finds moved files by name and size) and **Replace file…**
|
|
124
165
|
- **Projects** — a dashboard of every project with pictures, notes and tags: open, create from a canvas or a saved project template, duplicate, rename, archive and delete, import an old project file; media is shared, so copies cost no footage
|
|
@@ -451,7 +492,7 @@ Three equivalent control surfaces:
|
|
|
451
492
|
`fablecut_get_project`, `fablecut_set_project`, `fablecut_patch_project`,
|
|
452
493
|
`fablecut_import_media`, `fablecut_analyze_reference`, `fablecut_frame`,
|
|
453
494
|
`fablecut_encode_profiles`, `fablecut_normalize_audio`, `fablecut_auto_duck`,
|
|
454
|
-
`fablecut_denoise`, `fablecut_export`, `fablecut_scopes`, `fablecut_track`.
|
|
495
|
+
`fablecut_denoise`, `fablecut_silence`, `fablecut_beats`, `fablecut_reframe`, `fablecut_highlights`, `fablecut_transcribe`, `fablecut_captions`, `fablecut_export`, `fablecut_scopes`, `fablecut_track`.
|
|
455
496
|
|
|
456
497
|
FableCut is also published on the **official MCP registry** as
|
|
457
498
|
[`io.github.ronak-create/fablecut`](https://registry.modelcontextprotocol.io/v0/servers?search=fablecut)
|
|
@@ -634,19 +675,13 @@ examples in [`library/svg/`](library/svg/).
|
|
|
634
675
|
- Export runs in the browser because the compositor *is* the browser; agents
|
|
635
676
|
ask you to click Export (or render directly with ffmpeg from `media/`).
|
|
636
677
|
|
|
637
|
-
## Sponsors
|
|
638
|
-
|
|
639
|
-
<a href="https://fluxionai.space/register?source=github&campaign=github-sidrune-fablecut&promo=SDRFABLECUT" target="_blank" rel="noopener noreferrer sponsored">
|
|
640
|
-
<img src="docs/sponsors/sidrune-ai-banner.png" alt="Sidrune AI — one API for GPT, Claude and other leading AI models" width="640">
|
|
641
|
-
</a>
|
|
642
|
-
|
|
643
|
-
**[Sidrune AI](https://fluxionai.space/register?source=github&campaign=github-sidrune-fablecut&promo=SDRFABLECUT)** — One API for GPT, Claude, and other leading AI models. Sign up and get $3 in API credit.
|
|
644
|
-
|
|
645
678
|
## Community
|
|
646
679
|
|
|
647
680
|
Questions, ideas, showing off an edit, or want to help shape what's next? Join
|
|
648
681
|
the **[FableCut Discord](https://discord.gg/EFMQH7d6Tv)**. Bugs and feature
|
|
649
682
|
requests are still best filed as [GitHub issues](https://github.com/ronak-create/FableCut/issues).
|
|
683
|
+
Rather email? Write to [hello@fablecut.space](mailto:hello@fablecut.space), or
|
|
684
|
+
[support@fablecut.space](mailto:support@fablecut.space) for help.
|
|
650
685
|
|
|
651
686
|
## License
|
|
652
687
|
|
package/analyze.js
CHANGED
|
@@ -15,6 +15,7 @@ const fs = require("fs");
|
|
|
15
15
|
const path = require("path");
|
|
16
16
|
const { spawn } = require("child_process");
|
|
17
17
|
const Stats = require("./frame-stats");
|
|
18
|
+
const Beats = require("./beats");
|
|
18
19
|
|
|
19
20
|
const SR = 22050; // analysis sample rate
|
|
20
21
|
const HOP = 512; // onset-envelope hop size (~23 ms)
|
|
@@ -86,103 +87,9 @@ async function decodePCM(file) {
|
|
|
86
87
|
return new Int16Array(buf.buffer, buf.byteOffset, Math.floor(buf.length / 2));
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/* beats, BPM, energy curve and drop: beats.js, shared with the editor's Beats section and fablecut_beats */
|
|
89
91
|
function analyzeAudio(pcm) {
|
|
90
|
-
|
|
91
|
-
if (nFrames < 20) return { beats: [], bpm: null, energy: { step: 0.5, values: [] }, drop: null };
|
|
92
|
-
|
|
93
|
-
// frame energies
|
|
94
|
-
const E = new Float64Array(nFrames);
|
|
95
|
-
for (let i = 0; i < nFrames; i++) {
|
|
96
|
-
let s = 0;
|
|
97
|
-
const o = i * HOP;
|
|
98
|
-
for (let j = 0; j < WIN; j++) { const x = pcm[o + j] / 32768; s += x * x; }
|
|
99
|
-
E[i] = s / WIN;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// onset envelope: energy rise vs. trailing average
|
|
103
|
-
const O = new Float64Array(nFrames);
|
|
104
|
-
for (let i = 1; i < nFrames; i++) {
|
|
105
|
-
let m = 0, k = 0;
|
|
106
|
-
for (let j = Math.max(0, i - 8); j < i; j++) { m += E[j]; k++; }
|
|
107
|
-
O[i] = Math.max(0, E[i] - m / k);
|
|
108
|
-
}
|
|
109
|
-
let oMax = 0;
|
|
110
|
-
for (let i = 0; i < nFrames; i++) if (O[i] > oMax) oMax = O[i];
|
|
111
|
-
if (oMax > 0) for (let i = 0; i < nFrames; i++) O[i] /= oMax;
|
|
112
|
-
|
|
113
|
-
// peak-pick beats: local max, above an adaptive floor, min 0.25 s apart
|
|
114
|
-
const frameT = (i) => Math.round(((i * HOP + WIN / 2) / SR) * 1000) / 1000;
|
|
115
|
-
const minGap = Math.round(0.25 * SR / HOP);
|
|
116
|
-
const halfWin = Math.round(1.0 * SR / HOP);
|
|
117
|
-
const beats = [];
|
|
118
|
-
let last = -minGap;
|
|
119
|
-
for (let i = 3; i < nFrames - 3; i++) {
|
|
120
|
-
if (O[i] < 0.05) continue;
|
|
121
|
-
let isMax = true;
|
|
122
|
-
for (let j = -3; j <= 3; j++) if (O[i + j] > O[i]) { isMax = false; break; }
|
|
123
|
-
if (!isMax) continue;
|
|
124
|
-
let m = 0, k = 0;
|
|
125
|
-
for (let j = Math.max(0, i - halfWin); j < Math.min(nFrames, i + halfWin); j++) { m += O[j]; k++; }
|
|
126
|
-
if (O[i] < (m / k) * 1.5) continue;
|
|
127
|
-
if (i - last < minGap) continue;
|
|
128
|
-
beats.push(frameT(i));
|
|
129
|
-
last = i;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// BPM: autocorrelation of the onset envelope over 60–200 BPM lags,
|
|
133
|
-
// with a mild prior toward ~120; fold octaves into 70–180.
|
|
134
|
-
let bpm = null;
|
|
135
|
-
const lagMin = Math.round(60 / 200 * SR / HOP), lagMax = Math.round(60 / 60 * SR / HOP);
|
|
136
|
-
let best = 0, bestLag = 0;
|
|
137
|
-
for (let lag = lagMin; lag <= Math.min(lagMax, nFrames - 1); lag++) {
|
|
138
|
-
let s = 0;
|
|
139
|
-
for (let i = 0; i + lag < nFrames; i++) s += O[i] * O[i + lag];
|
|
140
|
-
const cand = 60 / (lag * HOP / SR);
|
|
141
|
-
const w = Math.exp(-0.5 * Math.pow(Math.log2(cand / 120) / 1.0, 2));
|
|
142
|
-
if (s * w > best) { best = s * w; bestLag = lag; }
|
|
143
|
-
}
|
|
144
|
-
if (bestLag) {
|
|
145
|
-
bpm = 60 / (bestLag * HOP / SR);
|
|
146
|
-
while (bpm < 70) bpm *= 2;
|
|
147
|
-
while (bpm > 180) bpm /= 2;
|
|
148
|
-
// refine: if the picked beats are regular, the median inter-beat interval
|
|
149
|
-
// is a much finer tempo estimate than the autocorrelation lag grid
|
|
150
|
-
if (beats.length >= 6) {
|
|
151
|
-
const gaps = beats.slice(1).map((t, i) => t - beats[i]).sort((a, b) => a - b);
|
|
152
|
-
const med = gaps[Math.floor(gaps.length / 2)];
|
|
153
|
-
const spread = gaps[Math.floor(gaps.length * 0.85)] - gaps[Math.floor(gaps.length * 0.15)];
|
|
154
|
-
if (med > 0 && spread < med * 0.15) {
|
|
155
|
-
// full span / count averages out the hop-grid quantization of each beat
|
|
156
|
-
let refined = 60 / ((beats[beats.length - 1] - beats[0]) / (beats.length - 1));
|
|
157
|
-
while (refined < 70) refined *= 2;
|
|
158
|
-
while (refined > 180) refined /= 2;
|
|
159
|
-
if (Math.abs(refined - bpm) / bpm < 0.15) bpm = refined;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
bpm = Math.round(bpm * 10) / 10;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// loudness curve, one value per 0.5 s, normalized 0–100
|
|
166
|
-
const step = 0.5;
|
|
167
|
-
const perStep = Math.round(step * SR / HOP);
|
|
168
|
-
const values = [];
|
|
169
|
-
for (let i = 0; i < nFrames; i += perStep) {
|
|
170
|
-
let s = 0, k = 0;
|
|
171
|
-
for (let j = i; j < Math.min(nFrames, i + perStep); j++) { s += Math.sqrt(E[j]); k++; }
|
|
172
|
-
values.push(k ? s / k : 0);
|
|
173
|
-
}
|
|
174
|
-
const vMax = Math.max(...values, 1e-9);
|
|
175
|
-
const energy = values.map((v) => Math.round(v / vMax * 100));
|
|
176
|
-
|
|
177
|
-
// the drop: biggest sustained energy rise (skip the very start)
|
|
178
|
-
let drop = null, bestRise = 0;
|
|
179
|
-
for (let i = 2; i < energy.length - 1; i++) {
|
|
180
|
-
const before = (energy[i - 2] + energy[i - 1]) / 2;
|
|
181
|
-
const after = (energy[i] + energy[Math.min(i + 1, energy.length - 1)]) / 2;
|
|
182
|
-
if (after - before > bestRise && after > 55) { bestRise = after - before; drop = Math.round(i * step * 10) / 10; }
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return { beats, bpm, energy: { step, values: energy }, drop };
|
|
92
|
+
return Beats.analyze(pcm, { scale: 1 / 32768 });
|
|
186
93
|
}
|
|
187
94
|
|
|
188
95
|
/* ── Extract the reference's music track into its own audio file ── */
|