@softure-ai/marketing-kit 0.6.0 → 0.7.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/CHANGELOG.md +55 -0
- package/README.md +64 -8
- package/dist/cli/footage.d.ts.map +1 -1
- package/dist/cli/footage.js +5 -2
- package/dist/cli/footage.js.map +1 -1
- package/dist/compose/compose.d.ts.map +1 -1
- package/dist/compose/compose.js +3 -3
- package/dist/compose/compose.js.map +1 -1
- package/dist/compose/timeline.d.ts +16 -0
- package/dist/compose/timeline.d.ts.map +1 -1
- package/dist/compose/timeline.js +17 -1
- package/dist/compose/timeline.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +18 -2
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +16 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +50 -3
- package/dist/config/schema.js.map +1 -1
- package/dist/footage/captions.d.ts +5 -1
- package/dist/footage/captions.d.ts.map +1 -1
- package/dist/footage/captions.js +6 -2
- package/dist/footage/captions.js.map +1 -1
- package/dist/footage/compose.d.ts +13 -2
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +75 -23
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/cuts.d.ts +44 -0
- package/dist/footage/cuts.d.ts.map +1 -0
- package/dist/footage/cuts.js +83 -0
- package/dist/footage/cuts.js.map +1 -0
- package/dist/footage/draft.d.ts +17 -3
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +28 -14
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +2 -1
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +5 -2
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +42 -3
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +7 -1
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/loudness.d.ts +20 -3
- package/dist/footage/loudness.d.ts.map +1 -1
- package/dist/footage/loudness.js +36 -18
- package/dist/footage/loudness.js.map +1 -1
- package/dist/footage/music.d.ts +3 -0
- package/dist/footage/music.d.ts.map +1 -1
- package/dist/footage/music.js +5 -0
- package/dist/footage/music.js.map +1 -1
- package/dist/footage/normalize.d.ts +9 -0
- package/dist/footage/normalize.d.ts.map +1 -1
- package/dist/footage/normalize.js +8 -4
- package/dist/footage/normalize.js.map +1 -1
- package/dist/footage/picture.d.ts +42 -0
- package/dist/footage/picture.d.ts.map +1 -0
- package/dist/footage/picture.js +141 -0
- package/dist/footage/picture.js.map +1 -0
- package/dist/footage/pipeline.d.ts +46 -1
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +128 -19
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/publish.d.ts +4 -2
- package/dist/footage/publish.d.ts.map +1 -1
- package/dist/footage/publish.js +8 -5
- package/dist/footage/publish.js.map +1 -1
- package/dist/footage/render.d.ts +17 -2
- package/dist/footage/render.d.ts.map +1 -1
- package/dist/footage/render.js +62 -13
- package/dist/footage/render.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/docker/footage-worker.Dockerfile +1 -0
- package/package.json +1 -1
- package/schema/marketing.schema.json +105 -4
- package/src/cli/footage.ts +4 -2
- package/src/compose/compose.ts +13 -3
- package/src/compose/timeline.ts +27 -1
- package/src/config/config.ts +18 -2
- package/src/config/schema.ts +52 -3
- package/src/footage/captions.ts +6 -2
- package/src/footage/compose.ts +86 -23
- package/src/footage/cuts.ts +104 -0
- package/src/footage/draft.ts +43 -14
- package/src/footage/edl.ts +5 -2
- package/src/footage/film.ts +47 -4
- package/src/footage/loudness.ts +38 -16
- package/src/footage/music.ts +7 -0
- package/src/footage/normalize.ts +8 -4
- package/src/footage/picture.ts +179 -0
- package/src/footage/pipeline.ts +166 -22
- package/src/footage/publish.ts +8 -5
- package/src/footage/render.ts +72 -13
- package/src/index.ts +36 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/footage/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/footage/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAgF,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1I,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAwD,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAcrH,iJAAiJ;AACjJ,eAAO,MAAM,YAAY,QAA4C,CAAC;AAGtE,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,gDAAgD;IAChD,SAAS,EAAE,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compose/html.js";
|
|
2
|
-
import { captionChunks } from "../compose/timeline.js";
|
|
2
|
+
import { CAPTION_LINE_HEIGHT, captionChunks, getCaptionPillCss, getCaptionPositionCss } from "../compose/timeline.js";
|
|
3
3
|
import { getCaptionSpans, phraseChunks } from "./captions.js";
|
|
4
4
|
import { getEdlDuration, getSegmentStarts } from "./edl.js";
|
|
5
|
-
import { DEFAULT_EDIT, getFootageEdit } from "./film.js";
|
|
5
|
+
import { CAPTION_MIN_FONT_SCALE, DEFAULT_EDIT, getFootageEdit } from "./film.js";
|
|
6
6
|
import { FOOTAGE_FPS } from "./normalize.js";
|
|
7
7
|
const r3 = (value) => Math.round(value * 1000) / 1000 || 0;
|
|
8
8
|
/**
|
|
9
9
|
* The HyperFrames composition of a footage film (the same 0.8.85 contract as `composeFilm`): one `<video>` clip per
|
|
10
10
|
* EDL segment over the normalized clip with its media start, the transitions (`fade` cross-fades from the segment
|
|
11
|
-
* before over `fadeFrames`, `zoom` punches in by `zoomPercent` on alternate jump cuts, `whoosh` plays the whoosh
|
|
11
|
+
* before over `fadeFrames`, `zoom` punches in by `zoomPercent` on alternate jump cuts, eased over `zoomEaseFrames`, `whoosh` plays the whoosh
|
|
12
12
|
* sound), a slow zoom on `kenburns` segments, the captions (plain phrases, or the word-highlight pill), the end card
|
|
13
13
|
* over the cut's last frame (its whoosh only with `isEndCardWhoosh`), the cut speech track and the ducked music.
|
|
14
14
|
*/
|
|
@@ -32,6 +32,17 @@ export function getSegmentScales(edl, zoomPercent = DEFAULT_EDIT.zoomPercent) {
|
|
|
32
32
|
});
|
|
33
33
|
return scales;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The frames each segment's zoom eases over (`zoomEaseFrames`, at most the segment's own frames): a `zoom` cut after
|
|
37
|
+
* the first segment that changes the scale and is not `kenburns` (its slow zoom owns the scale); 0 for every other.
|
|
38
|
+
*/
|
|
39
|
+
export function getSegmentZoomEases(edl, edit) {
|
|
40
|
+
const scales = getSegmentScales(edl, edit.zoomPercent);
|
|
41
|
+
return edl.segments.map((segment, index) => {
|
|
42
|
+
const isEased = edit.zoomEaseFrames > 0 && index > 0 && segment.transition === "zoom" && segment.motion !== "kenburns" && scales[index - 1] !== scales[index];
|
|
43
|
+
return isEased ? Math.max(1, Math.min(edit.zoomEaseFrames, Math.floor((segment.end - segment.start) * FOOTAGE_FPS))) : 0;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
35
46
|
export function composeFootage(input) {
|
|
36
47
|
const { film, edl, words, frame, colors: c, fonts, assets, caption: captionBox } = input;
|
|
37
48
|
const starts = getSegmentStarts(edl);
|
|
@@ -39,29 +50,42 @@ export function composeFootage(input) {
|
|
|
39
50
|
const end = getFootageFilmSeconds(film, edl);
|
|
40
51
|
const edit = getFootageEdit(film);
|
|
41
52
|
const scales = getSegmentScales(edl, edit.zoomPercent);
|
|
53
|
+
const eases = getSegmentZoomEases(edl, edit);
|
|
42
54
|
const fadeSeconds = r3(edit.fadeFrames / FOOTAGE_FPS);
|
|
43
55
|
const kenBurnsScale = 1 + (edit.kenBurnsPercent > 0 ? edit.kenBurnsPercent : HAND_KEN_BURNS_PERCENT) / 100;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const picture = assets.picture;
|
|
57
|
+
const segments = picture === undefined
|
|
58
|
+
? edl.segments.map((segment, index) => {
|
|
59
|
+
const src = assets.clips[segment.clip];
|
|
60
|
+
if (src === undefined)
|
|
61
|
+
throw new Error(`The EDL names clip "${segment.clip}", which the film has no file for.`);
|
|
62
|
+
const next = edl.segments[index + 1];
|
|
63
|
+
const tail = next?.transition === "fade" ? fadeSeconds : 0;
|
|
64
|
+
const start = starts[index];
|
|
65
|
+
const duration = r3(segment.end - segment.start + tail);
|
|
66
|
+
const scale = scales[index];
|
|
67
|
+
const style = scale === 1 ? "" : ` style="transform:scale(${scale})"`;
|
|
68
|
+
return `<video id="seg${index}" class="clip shot" src="${escapeHtml(src)}" data-start="${start}" data-media-start="${segment.start}" data-duration="${duration}"${style} muted playsinline></video>`;
|
|
69
|
+
})
|
|
70
|
+
: [`<video id="picture" class="clip shot" src="${escapeHtml(picture)}" data-start="0" data-media-start="0" data-duration="${cutEnd}" muted playsinline></video>`];
|
|
56
71
|
const tweens = [];
|
|
57
72
|
edl.segments.forEach((segment, index) => {
|
|
58
73
|
const start = starts[index];
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
const scale = scales[index];
|
|
75
|
+
const target = picture === undefined ? `#seg${index}` : "#picture";
|
|
76
|
+
// One video carries every segment: each one sets the zoom it starts at (a fade is already in the picture).
|
|
77
|
+
if (picture !== undefined)
|
|
78
|
+
tweens.push(`tl.set("#picture", { scale: ${scale} }, ${start});`);
|
|
79
|
+
if (picture === undefined && segment.transition === "fade" && index > 0) {
|
|
80
|
+
tweens.push(`tl.fromTo("${target}", { opacity: 0 }, { opacity: 1, duration: ${fadeSeconds}, ease: "none", immediateRender: false }, ${start});`);
|
|
81
|
+
}
|
|
82
|
+
const ease = eases[index];
|
|
83
|
+
if (ease > 0) {
|
|
84
|
+
// Eases from the scale on screen before the cut, so the punch-in (or back out) reads as one move of the camera.
|
|
85
|
+
tweens.push(`tl.fromTo("${target}", { scale: ${scales[index - 1]} }, { scale: ${scales[index]}, duration: ${r3(ease / FOOTAGE_FPS)}, ease: "power1.out", immediateRender: false }, ${start});`);
|
|
61
86
|
}
|
|
62
87
|
if (segment.motion === "kenburns") {
|
|
63
|
-
|
|
64
|
-
tweens.push(`tl.fromTo("#seg${index}", { scale: ${from} }, { scale: ${r3(from * kenBurnsScale)}, duration: ${r3(segment.end - segment.start)}, ease: "none", immediateRender: false }, ${start});`);
|
|
88
|
+
tweens.push(`tl.fromTo("${target}", { scale: ${scale} }, { scale: ${r3(scale * kenBurnsScale)}, duration: ${r3(segment.end - segment.start)}, ease: "none", immediateRender: false }, ${start});`);
|
|
65
89
|
}
|
|
66
90
|
});
|
|
67
91
|
// --- Captions: plain phrases, or the pill that lights each word ---
|
|
@@ -77,6 +101,7 @@ export function composeFootage(input) {
|
|
|
77
101
|
return `<div id="cap${i}" class="clip caption" data-start="${start}" data-duration="${r3(stop - start)}">${box}</div>`;
|
|
78
102
|
})
|
|
79
103
|
.join("\n ");
|
|
104
|
+
const captionFit = film.captions && film.captionMaxLines !== undefined ? getCaptionFitScript(film.captionMaxLines, Math.round(captionBox.fontSize * CAPTION_MIN_FONT_SCALE)) : "";
|
|
80
105
|
// --- Sound ---
|
|
81
106
|
const sfx = [];
|
|
82
107
|
const play = (event, t, volume, dur) => {
|
|
@@ -135,10 +160,10 @@ html,body{width:${frame.width}px;height:${frame.height}px;overflow:hidden;backgr
|
|
|
135
160
|
#root{position:relative;width:${frame.width}px;height:${frame.height}px;overflow:hidden;background:#000;font-family:${bodyFont};color:${c.foreground}}
|
|
136
161
|
.shot{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transform-origin:50% 42%}
|
|
137
162
|
.shade{position:absolute;inset:0;background:${c.background};opacity:0}
|
|
138
|
-
.caption{position:absolute;left:${captionBox.left}px;right:${captionBox.right}px
|
|
139
|
-
.pill{
|
|
163
|
+
.caption{position:absolute;left:${captionBox.left}px;right:${captionBox.right}px;${getCaptionPositionCss(captionBox)};display:flex;justify-content:center}
|
|
164
|
+
.pill{${getCaptionPillCss(captionBox.fontSize)};border-radius:22px;background:${c.captionBackground};box-shadow:0 14px 44px rgba(0,0,0,.5);color:${c.captionText}}
|
|
140
165
|
.pill span{display:inline-block}
|
|
141
|
-
.phrase{font-weight:650;font-size:${captionBox.fontSize}px;line-height
|
|
166
|
+
.phrase{font-weight:650;font-size:${captionBox.fontSize}px;line-height:${CAPTION_LINE_HEIGHT};letter-spacing:-.01em;text-align:center;color:#fff;text-shadow:0 2px 6px rgba(0,0,0,.55),0 0 18px rgba(0,0,0,.35)}
|
|
142
167
|
.endcard{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0 80px;text-align:center}
|
|
143
168
|
.brand{display:flex;justify-content:center;align-items:center;gap:18px;font-family:${headingFont};font-size:46px}
|
|
144
169
|
.logo{height:60px;width:auto}
|
|
@@ -154,7 +179,7 @@ html,body{width:${frame.width}px;height:${frame.height}px;overflow:hidden;backgr
|
|
|
154
179
|
${captionHtml}
|
|
155
180
|
${audio}
|
|
156
181
|
</div>
|
|
157
|
-
<script>
|
|
182
|
+
${captionFit}<script>
|
|
158
183
|
const tl = gsap.timeline({ paused: true });
|
|
159
184
|
${tweens.join("\n")}
|
|
160
185
|
const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : [])};
|
|
@@ -171,4 +196,31 @@ window.__timelines["${COMPOSITION_ID}"] = tl;
|
|
|
171
196
|
</html>
|
|
172
197
|
`;
|
|
173
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* A page script that shrinks each caption's font in 1 px steps until its text takes at most `maxLines` lines, or the
|
|
201
|
+
* font reaches `minFontSize`. Only the browser knows how the font wraps, so it measures there: once at load and again
|
|
202
|
+
* when the fonts are ready (hyperframes waits for them before the first frame). Hidden clips keep their layout.
|
|
203
|
+
*/
|
|
204
|
+
function getCaptionFitScript(maxLines, minFontSize) {
|
|
205
|
+
return `<script>
|
|
206
|
+
(() => {
|
|
207
|
+
const captionMaxLines = ${maxLines}, captionMinFontSize = ${minFontSize};
|
|
208
|
+
const countLines = (el) => {
|
|
209
|
+
const style = getComputedStyle(el);
|
|
210
|
+
return Math.round((el.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom)) / parseFloat(style.lineHeight));
|
|
211
|
+
};
|
|
212
|
+
const fit = () => document.querySelectorAll(".caption > p").forEach((el) => {
|
|
213
|
+
el.style.fontSize = "";
|
|
214
|
+
let size = parseFloat(getComputedStyle(el).fontSize);
|
|
215
|
+
while (countLines(el) > captionMaxLines && size > captionMinFontSize) {
|
|
216
|
+
size -= 1;
|
|
217
|
+
el.style.fontSize = size + "px";
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
fit();
|
|
221
|
+
if (document.fonts) document.fonts.ready.then(fit);
|
|
222
|
+
})();
|
|
223
|
+
</script>
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
174
226
|
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/footage/compose.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAsB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/footage/compose.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAsB,MAAM,wBAAwB,CAAC;AAE1I,OAAO,EAAE,eAAe,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAY,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,cAAc,EAAsC,MAAM,WAAW,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,EAAE,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;AAE3E;;;;;;GAMG;AAEH,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,iJAAiJ;AACjJ,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,UA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BAAmB;;qFAEP,WAAW;;wBAExE,WAAW,8BAA8B,KAAK,CAAC,YAAY;uHACoC,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,GAAG;6CACrG,CAAC,CAAC,KAAK;;;;sCAId,cAAc,mCAAmC,GAAG,iBAAiB,KAAK,CAAC,KAAK,kBAAkB,KAAK,CAAC,MAAM;IAChJ,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IACrB,WAAW;IACX,WAAW;IACX,KAAK;;EAEP,UAAU;;EAEV,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;mBACA,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;;;qEAGxC,CAAC,CAAC,WAAW,kBAAkB,CAAC,CAAC,gBAAgB,qFAAqF,CAAC,CAAC,WAAW;;EAEtN,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;iBACT,GAAG;;sBAEE,cAAc;;;;CAInC,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,QAAgB,EAAE,WAAmB;IAChE,OAAO;;4BAEmB,QAAQ,0BAA0B,WAAW;;;;;;;;;;;;;;;;;CAiBxE,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Edl } from "./edl.js";
|
|
2
|
+
/**
|
|
3
|
+
* Transitions chosen from the frames around each jump cut (`transitions.jump: "auto"`): the last frame before a cut
|
|
4
|
+
* and the first after it, both from the normalized clips, are shrunk to a small gray thumbnail and compared. A small
|
|
5
|
+
* difference (the same framing, a removed filler) gets an eased punch-in (`zoom`), a large one (the camera moved) a
|
|
6
|
+
* short dissolve (`fade`). Deterministic and local: ffmpeg only, no provider.
|
|
7
|
+
*/
|
|
8
|
+
/** The thumbnail both frames are compared at: small enough that handheld shake and noise average out. */
|
|
9
|
+
export declare const CUT_THUMBNAIL: {
|
|
10
|
+
readonly width: 48;
|
|
11
|
+
readonly height: 48;
|
|
12
|
+
};
|
|
13
|
+
/** What the frames around one cut measured and the transition it got. */
|
|
14
|
+
export interface CutMeasure {
|
|
15
|
+
/** The id of the segment the cut starts. */
|
|
16
|
+
segment: string;
|
|
17
|
+
/** The mean absolute difference of the two thumbnails' gray levels, 0 (the same) to 1 (black against white). */
|
|
18
|
+
difference: number;
|
|
19
|
+
transition: "zoom" | "fade";
|
|
20
|
+
}
|
|
21
|
+
/** The mean absolute difference of two gray frames of the same size, 0-1. */
|
|
22
|
+
export declare function measureFrameDifference(before: Uint8Array, after: Uint8Array): number;
|
|
23
|
+
/** `fade` from `threshold` up (the picture moved), `zoom` below it (the same shot). */
|
|
24
|
+
export declare function chooseCutTransition(difference: number, threshold?: number): "zoom" | "fade";
|
|
25
|
+
/** One frame of a clip at `seconds` as a raw gray thumbnail (`CUT_THUMBNAIL`). */
|
|
26
|
+
export declare function buildCutFrameArgs(file: string, seconds: number, output: string): string[];
|
|
27
|
+
/** The indexes of the jump cuts the auto choice sets: a plain cut inside one clip, after the first segment. */
|
|
28
|
+
export declare function findAutoCuts(edl: Edl): number[];
|
|
29
|
+
export interface ChooseCutTransitionsOptions {
|
|
30
|
+
/** The difference from which a cut fades; default `DEFAULT_AUTO_THRESHOLD`. */
|
|
31
|
+
threshold?: number;
|
|
32
|
+
/** A folder for the thumbnails; created, and removed when done. */
|
|
33
|
+
workDir: string;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Measures every plain jump cut of `edl` (`findAutoCuts`) on the normalized clips and gives it `zoom` or `fade`. Cuts
|
|
38
|
+
* between clips and every other transition stay as they are. Answers the new EDL and what each cut measured.
|
|
39
|
+
*/
|
|
40
|
+
export declare function chooseCutTransitions(edl: Edl, clips: Record<string, string>, options: ChooseCutTransitionsOptions): Promise<{
|
|
41
|
+
edl: Edl;
|
|
42
|
+
cuts: CutMeasure[];
|
|
43
|
+
}>;
|
|
44
|
+
//# sourceMappingURL=cuts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cuts.d.ts","sourceRoot":"","sources":["../../src/footage/cuts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAKpC;;;;;GAKG;AAEH,yGAAyG;AACzG,eAAO,MAAM,aAAa;;;CAAqC,CAAC;AAEhE,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,gHAAgH;IAChH,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAID,6EAA6E;AAC7E,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAOpF;AAED,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,GAAE,MAA+B,GAAG,MAAM,GAAG,MAAM,CAEnH;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAGzF;AAED,+GAA+G;AAC/G,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,CAK/C;AAED,MAAM,WAAW,2BAA2B;IAC1C,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAiCnK"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { DEFAULT_AUTO_THRESHOLD } from "./film.js";
|
|
4
|
+
import { FOOTAGE_FPS } from "./normalize.js";
|
|
5
|
+
import { runFfmpeg } from "./process.js";
|
|
6
|
+
/**
|
|
7
|
+
* Transitions chosen from the frames around each jump cut (`transitions.jump: "auto"`): the last frame before a cut
|
|
8
|
+
* and the first after it, both from the normalized clips, are shrunk to a small gray thumbnail and compared. A small
|
|
9
|
+
* difference (the same framing, a removed filler) gets an eased punch-in (`zoom`), a large one (the camera moved) a
|
|
10
|
+
* short dissolve (`fade`). Deterministic and local: ffmpeg only, no provider.
|
|
11
|
+
*/
|
|
12
|
+
/** The thumbnail both frames are compared at: small enough that handheld shake and noise average out. */
|
|
13
|
+
export const CUT_THUMBNAIL = { width: 48, height: 48 };
|
|
14
|
+
const r4 = (value) => Math.round(value * 10000) / 10000 || 0;
|
|
15
|
+
/** The mean absolute difference of two gray frames of the same size, 0-1. */
|
|
16
|
+
export function measureFrameDifference(before, after) {
|
|
17
|
+
if (before.length === 0 || before.length !== after.length) {
|
|
18
|
+
throw new Error(`Comparing the frames around a cut needs two frames of one size, got ${before.length} and ${after.length} bytes.`);
|
|
19
|
+
}
|
|
20
|
+
let sum = 0;
|
|
21
|
+
for (let index = 0; index < before.length; index++)
|
|
22
|
+
sum += Math.abs(before[index] - after[index]);
|
|
23
|
+
return r4(sum / before.length / 255);
|
|
24
|
+
}
|
|
25
|
+
/** `fade` from `threshold` up (the picture moved), `zoom` below it (the same shot). */
|
|
26
|
+
export function chooseCutTransition(difference, threshold = DEFAULT_AUTO_THRESHOLD) {
|
|
27
|
+
return difference >= threshold ? "fade" : "zoom";
|
|
28
|
+
}
|
|
29
|
+
/** One frame of a clip at `seconds` as a raw gray thumbnail (`CUT_THUMBNAIL`). */
|
|
30
|
+
export function buildCutFrameArgs(file, seconds, output) {
|
|
31
|
+
const { width, height } = CUT_THUMBNAIL;
|
|
32
|
+
return ["-v", "error", "-y", "-ss", String(seconds), "-i", file, "-frames:v", "1", "-vf", `scale=${width}:${height}:flags=area,format=gray`, "-f", "rawvideo", output];
|
|
33
|
+
}
|
|
34
|
+
/** The indexes of the jump cuts the auto choice sets: a plain cut inside one clip, after the first segment. */
|
|
35
|
+
export function findAutoCuts(edl) {
|
|
36
|
+
return edl.segments.flatMap((segment, index) => {
|
|
37
|
+
const previous = edl.segments[index - 1];
|
|
38
|
+
return previous !== undefined && previous.clip === segment.clip && segment.transition === "cut" ? [index] : [];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Measures every plain jump cut of `edl` (`findAutoCuts`) on the normalized clips and gives it `zoom` or `fade`. Cuts
|
|
43
|
+
* between clips and every other transition stay as they are. Answers the new EDL and what each cut measured.
|
|
44
|
+
*/
|
|
45
|
+
export async function chooseCutTransitions(edl, clips, options) {
|
|
46
|
+
const threshold = options.threshold ?? DEFAULT_AUTO_THRESHOLD;
|
|
47
|
+
if (!(threshold >= 0 && threshold <= 1))
|
|
48
|
+
throw new Error(`transitions.autoThreshold must be between 0 and 1, got ${String(threshold)}.`);
|
|
49
|
+
const indexes = findAutoCuts(edl);
|
|
50
|
+
if (indexes.length === 0)
|
|
51
|
+
return { edl, cuts: [] };
|
|
52
|
+
const signal = options.signal === undefined ? {} : { signal: options.signal };
|
|
53
|
+
const getClip = (id) => {
|
|
54
|
+
const file = clips[id];
|
|
55
|
+
if (file === undefined)
|
|
56
|
+
throw new Error(`No file for clip "${id}" of the EDL.`);
|
|
57
|
+
return file;
|
|
58
|
+
};
|
|
59
|
+
mkdirSync(options.workDir, { recursive: true });
|
|
60
|
+
const segments = [...edl.segments];
|
|
61
|
+
const cuts = [];
|
|
62
|
+
try {
|
|
63
|
+
for (const index of indexes) {
|
|
64
|
+
const segment = segments[index];
|
|
65
|
+
const previous = segments[index - 1];
|
|
66
|
+
const beforeFile = join(options.workDir, `${segment.id}-before.gray`);
|
|
67
|
+
const afterFile = join(options.workDir, `${segment.id}-after.gray`);
|
|
68
|
+
// The last frame the cut shows before it, and the first after it.
|
|
69
|
+
const beforeAt = Math.round(Math.max(previous.start, previous.end - 1 / FOOTAGE_FPS) * 1000) / 1000;
|
|
70
|
+
await runFfmpeg(`The frame before cut ${segment.id}`, buildCutFrameArgs(getClip(previous.clip), beforeAt, beforeFile), { ...signal, output: beforeFile });
|
|
71
|
+
await runFfmpeg(`The frame after cut ${segment.id}`, buildCutFrameArgs(getClip(segment.clip), segment.start, afterFile), { ...signal, output: afterFile });
|
|
72
|
+
const difference = measureFrameDifference(readFileSync(beforeFile), readFileSync(afterFile));
|
|
73
|
+
const transition = chooseCutTransition(difference, threshold);
|
|
74
|
+
segments[index] = { ...segment, transition };
|
|
75
|
+
cuts.push({ segment: segment.id, difference, transition });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
rmSync(options.workDir, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
return { edl: { ...edl, segments }, cuts };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=cuts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cuts.js","sourceRoot":"","sources":["../../src/footage/cuts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MA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AAE,UAAU,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YAC1J,MAAM,SAAS,CAAC,uBAAuB,OAAO,CAAC,EAAE,EAAE,EAAE,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3J,MAAM,UAAU,GAAG,sBAAsB,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;YAC7F,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;YAC9D,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC;AAC7C,CAAC"}
|
package/dist/footage/draft.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type Frame } from "./normalize.js";
|
|
|
6
6
|
import { type FootageResult, type FootageRunOptions, type PreparedClip, type TranscribeOutcome } from "./pipeline.js";
|
|
7
7
|
/**
|
|
8
8
|
* A fast draft of a footage film, ffmpeg only (no hyperframes, no browser): the cut at a small width with the film's
|
|
9
|
-
* phrase captions burned in, its zoom cuts, cross-fades and Ken Burns b-roll drawn as the full render draws them, and
|
|
9
|
+
* phrase captions burned in, its zoom cuts (eased as in the render), cross-fades and Ken Burns b-roll drawn as the full render draws them, and
|
|
10
10
|
* the speech track. No loudness pass, music, end card or cover. What an app shows the owner before the paid render.
|
|
11
11
|
*/
|
|
12
12
|
/** The draft's default width: 540 makes a 540×960 draft of a 9:16 film. */
|
|
@@ -32,8 +32,8 @@ export interface FootageDraftCaptionsInput {
|
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* The draft's captions as an ASS subtitle file: the film's phrases (`phraseChunks`) shown for the render's spans
|
|
35
|
-
* (`getCaptionSpans`), white bold text with a dark outline and shadow, centred in the caption box from its top
|
|
36
|
-
* when the film has no captions or nothing is said.
|
|
35
|
+
* (`getCaptionSpans`), white bold text with a dark outline and shadow, centred in the caption box from its top (or
|
|
36
|
+
* from its foot, with `bottom`). Null when the film has no captions or nothing is said.
|
|
37
37
|
*/
|
|
38
38
|
export declare function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): string | null;
|
|
39
39
|
export interface FootageDraftArgsInput {
|
|
@@ -52,6 +52,11 @@ export interface FootageDraftArgsInput {
|
|
|
52
52
|
/** The folder libass loads the captions' font from, or null for the system's fonts. */
|
|
53
53
|
fontsDir: string | null;
|
|
54
54
|
output: string;
|
|
55
|
+
/**
|
|
56
|
+
* ffmpeg's threads for every segment's decoder, the filter graph and the encoder; by default ffmpeg's own choice,
|
|
57
|
+
* which follows the host's cores, not a container's CPU quota. A positive whole number.
|
|
58
|
+
*/
|
|
59
|
+
threads?: number;
|
|
55
60
|
}
|
|
56
61
|
/** A segment's picture as the draft plays it: how long its stream runs and the fade it starts with. */
|
|
57
62
|
export interface DraftSegmentPlan {
|
|
@@ -67,6 +72,10 @@ export interface DraftSegmentPlan {
|
|
|
67
72
|
scale: number;
|
|
68
73
|
/** The zoom it ends at: above `scale` for a `kenburns` segment, `scale` otherwise. */
|
|
69
74
|
endScale: number;
|
|
75
|
+
/** The zoom on screen before an eased `zoom` cut, which the segment eases from to `scale`; `scale` otherwise. */
|
|
76
|
+
startScale: number;
|
|
77
|
+
/** The frames the zoom eases over (`getSegmentZoomEases`); 0: the segment starts at `scale`. */
|
|
78
|
+
easeFrames: number;
|
|
70
79
|
}
|
|
71
80
|
/**
|
|
72
81
|
* How each segment plays in the draft. A `fade` cut lasts the film's `fadeFrames` (clamped to the incoming segment, so
|
|
@@ -86,6 +95,11 @@ export interface RenderFootageDraftOptions extends Pick<FootageRunOptions, "buil
|
|
|
86
95
|
width?: number;
|
|
87
96
|
/** A project's override of the format's caption box (`marketing.json` `layout`), as the render takes it. */
|
|
88
97
|
layout?: LayoutOverride;
|
|
98
|
+
/**
|
|
99
|
+
* ffmpeg's threads for the draft's decoders, filter graph and encoder (`buildFootageDraftArgs`); by default ffmpeg's
|
|
100
|
+
* own choice, which follows the host's cores. Set it from a CPU-limited container's quota.
|
|
101
|
+
*/
|
|
102
|
+
threads?: number;
|
|
89
103
|
}
|
|
90
104
|
export interface FootageDraft {
|
|
91
105
|
output: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/footage/draft.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAgD,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/footage/draft.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EAAgD,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC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AM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,YAAY,EAAE,EACrB,UAAU,EAAE,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,EACzD,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CA2CtC"}
|
package/dist/footage/draft.js
CHANGED
|
@@ -3,16 +3,16 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { ok } from "../voice/provider.js";
|
|
5
5
|
import { getCaptionSpans, getFootageCaptionLayout, phraseChunks } from "./captions.js";
|
|
6
|
-
import { getSegmentScales } from "./compose.js";
|
|
6
|
+
import { getSegmentScales, getSegmentZoomEases } from "./compose.js";
|
|
7
7
|
import { getEdlDuration, getSegmentStarts, remapWords } from "./edl.js";
|
|
8
8
|
import { getFootageEdit } from "./film.js";
|
|
9
|
-
import { FOOTAGE_FPS } from "./normalize.js";
|
|
9
|
+
import { FOOTAGE_FPS, getThreadArgs } from "./normalize.js";
|
|
10
10
|
import { getFrame } from "./pipeline.js";
|
|
11
11
|
import { runFfmpeg } from "./process.js";
|
|
12
|
-
import { buildSpeechArgs } from "./render.js";
|
|
12
|
+
import { buildSpeechArgs, getSpeechCutOptions } from "./render.js";
|
|
13
13
|
/**
|
|
14
14
|
* A fast draft of a footage film, ffmpeg only (no hyperframes, no browser): the cut at a small width with the film's
|
|
15
|
-
* phrase captions burned in, its zoom cuts, cross-fades and Ken Burns b-roll drawn as the full render draws them, and
|
|
15
|
+
* phrase captions burned in, its zoom cuts (eased as in the render), cross-fades and Ken Burns b-roll drawn as the full render draws them, and
|
|
16
16
|
* the speech track. No loudness pass, music, end card or cover. What an app shows the owner before the paid render.
|
|
17
17
|
*/
|
|
18
18
|
/** The draft's default width: 540 makes a 540×960 draft of a 9:16 film. */
|
|
@@ -50,8 +50,8 @@ function toAssText(text) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* The draft's captions as an ASS subtitle file: the film's phrases (`phraseChunks`) shown for the render's spans
|
|
53
|
-
* (`getCaptionSpans`), white bold text with a dark outline and shadow, centred in the caption box from its top
|
|
54
|
-
* when the film has no captions or nothing is said.
|
|
53
|
+
* (`getCaptionSpans`), white bold text with a dark outline and shadow, centred in the caption box from its top (or
|
|
54
|
+
* from its foot, with `bottom`). Null when the film has no captions or nothing is said.
|
|
55
55
|
*/
|
|
56
56
|
export function buildFootageDraftCaptions(input) {
|
|
57
57
|
if (!input.film.captions)
|
|
@@ -83,10 +83,11 @@ export function buildFootageDraftCaptions(input) {
|
|
|
83
83
|
1,
|
|
84
84
|
outline,
|
|
85
85
|
shadow,
|
|
86
|
-
8
|
|
86
|
+
// ASS alignment 2 hangs the text from MarginV above the bottom, 8 from MarginV below the top.
|
|
87
|
+
caption.bottom === undefined ? 8 : 2,
|
|
87
88
|
Math.round(caption.left),
|
|
88
89
|
Math.round(caption.right),
|
|
89
|
-
Math.round(caption.top),
|
|
90
|
+
Math.round(caption.bottom ?? caption.top),
|
|
90
91
|
1,
|
|
91
92
|
].join(",");
|
|
92
93
|
const events = chunks.map((chunk, index) => {
|
|
@@ -121,6 +122,7 @@ export function planFootageDraft(film, edl) {
|
|
|
121
122
|
const fadeSeconds = r3(edit.fadeFrames / FOOTAGE_FPS);
|
|
122
123
|
const kenBurnsScale = 1 + (edit.kenBurnsPercent > 0 ? edit.kenBurnsPercent : HAND_KEN_BURNS_PERCENT) / 100;
|
|
123
124
|
const scales = getSegmentScales(edl, edit.zoomPercent);
|
|
125
|
+
const eases = getSegmentZoomEases(edl, edit);
|
|
124
126
|
const starts = getSegmentStarts(edl);
|
|
125
127
|
const fades = edl.segments.map((segment, index) => (segment.transition === "fade" && index > 0 ? r3(Math.min(fadeSeconds, segment.end - segment.start)) : 0));
|
|
126
128
|
return edl.segments.map((segment, index) => {
|
|
@@ -132,19 +134,26 @@ export function planFootageDraft(film, edl) {
|
|
|
132
134
|
fade: fades[index],
|
|
133
135
|
scale,
|
|
134
136
|
endScale: segment.motion === "kenburns" ? r4(scale * kenBurnsScale) : scale,
|
|
137
|
+
startScale: eases[index] > 0 ? scales[index - 1] : scale,
|
|
138
|
+
easeFrames: eases[index],
|
|
135
139
|
};
|
|
136
140
|
});
|
|
137
141
|
}
|
|
138
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* The filters that zoom a segment's picture and scale it to the draft: a crop for a still zoom, `zoompan` for Ken Burns
|
|
144
|
+
* and for an eased zoom cut (the render's `power1.out`: `1 - (1 - t)^2`).
|
|
145
|
+
*/
|
|
139
146
|
function buildPictureFilters(plan, draft) {
|
|
140
147
|
const size = `${draft.width}:${draft.height}`;
|
|
148
|
+
const zoompan = (zoom) => `zoompan=z='${zoom}':x='(iw-iw/zoom)*${ZOOM_ORIGIN.x}':y='(ih-ih/zoom)*${ZOOM_ORIGIN.y}':d=1:s=${draft.width}x${draft.height}:fps=${FOOTAGE_FPS}`;
|
|
149
|
+
if (plan.easeFrames > 0) {
|
|
150
|
+
return [zoompan(`${plan.startScale}+(${r4(plan.scale - plan.startScale)})*(1-pow(1-min(on/${plan.easeFrames},1),2))`)];
|
|
151
|
+
}
|
|
141
152
|
if (plan.endScale !== plan.scale) {
|
|
142
153
|
// The zoom runs over the segment's own length, as the render's tween does, and holds through a fade's tail.
|
|
143
154
|
const frames = Math.max(1, Math.round(plan.length * FOOTAGE_FPS));
|
|
144
155
|
const zoom = `${plan.scale}+${r4(plan.endScale - plan.scale)}*min(on/${frames},1)`;
|
|
145
|
-
return [
|
|
146
|
-
`zoompan=z='${zoom}':x='(iw-iw/zoom)*${ZOOM_ORIGIN.x}':y='(ih-ih/zoom)*${ZOOM_ORIGIN.y}':d=1:s=${draft.width}x${draft.height}:fps=${FOOTAGE_FPS}`,
|
|
147
|
-
];
|
|
156
|
+
return [zoompan(zoom)];
|
|
148
157
|
}
|
|
149
158
|
if (plan.scale !== 1) {
|
|
150
159
|
return [`crop=iw/${plan.scale}:ih/${plan.scale}:(iw-iw/${plan.scale})*${ZOOM_ORIGIN.x}:(ih-ih/${plan.scale})*${ZOOM_ORIGIN.y}`, `scale=${size}`];
|
|
@@ -160,6 +169,7 @@ export function buildFootageDraftArgs(input) {
|
|
|
160
169
|
const { edl } = input;
|
|
161
170
|
const draft = getFootageDraftFrame(input.frame, input.width);
|
|
162
171
|
const plans = planFootageDraft(input.film, edl);
|
|
172
|
+
const threads = getThreadArgs(input.threads, "draft.threads");
|
|
163
173
|
const inputs = [];
|
|
164
174
|
const parts = [];
|
|
165
175
|
edl.segments.forEach((segment, index) => {
|
|
@@ -167,7 +177,8 @@ export function buildFootageDraftArgs(input) {
|
|
|
167
177
|
if (clip === undefined)
|
|
168
178
|
throw new Error(`No file for clip "${segment.clip}" of the EDL.`);
|
|
169
179
|
const plan = plans[index];
|
|
170
|
-
|
|
180
|
+
// Before an input, -threads sizes that input's decoder: one decoder runs per segment.
|
|
181
|
+
inputs.push(...threads.output, "-ss", String(r3(segment.start)), "-t", String(plan.seconds), "-i", clip);
|
|
171
182
|
const filters = [
|
|
172
183
|
"setpts=PTS-STARTPTS",
|
|
173
184
|
...buildPictureFilters(plan, draft),
|
|
@@ -205,6 +216,7 @@ export function buildFootageDraftArgs(input) {
|
|
|
205
216
|
"-v",
|
|
206
217
|
"error",
|
|
207
218
|
"-y",
|
|
219
|
+
...threads.global,
|
|
208
220
|
...inputs,
|
|
209
221
|
"-i",
|
|
210
222
|
input.speech,
|
|
@@ -230,6 +242,7 @@ export function buildFootageDraftArgs(input) {
|
|
|
230
242
|
DRAFT_AUDIO_BITRATE,
|
|
231
243
|
"-movflags",
|
|
232
244
|
"+faststart",
|
|
245
|
+
...threads.output,
|
|
233
246
|
input.output,
|
|
234
247
|
];
|
|
235
248
|
}
|
|
@@ -258,7 +271,7 @@ export async function renderFootageDraft(film, clips, transcript, edl, options)
|
|
|
258
271
|
const output = resolve(options.output);
|
|
259
272
|
mkdirSync(dirname(output), { recursive: true });
|
|
260
273
|
report("speech", 1, 0);
|
|
261
|
-
await runFfmpeg("The draft's speech track", buildSpeechArgs(edl, transcript.speech, speech), { ...aborting, output: speech, onSeconds: (done) => report("speech", 1, done) });
|
|
274
|
+
await runFfmpeg("The draft's speech track", buildSpeechArgs(edl, transcript.speech, speech, getSpeechCutOptions(getFootageEdit(film))), { ...aborting, output: speech, onSeconds: (done) => report("speech", 1, done) });
|
|
262
275
|
report("film", 2, 0);
|
|
263
276
|
// Run in the draft folder: the captions file and the font folder are relative names, so no path needs escaping in the filter graph.
|
|
264
277
|
const args = buildFootageDraftArgs({
|
|
@@ -268,6 +281,7 @@ export async function renderFootageDraft(film, clips, transcript, edl, options)
|
|
|
268
281
|
speech,
|
|
269
282
|
frame,
|
|
270
283
|
...(options.width === undefined ? {} : { width: options.width }),
|
|
284
|
+
...(options.threads === undefined ? {} : { threads: options.threads }),
|
|
271
285
|
captions: captions === null ? null : "captions.ass",
|
|
272
286
|
fontsDir: captions === null ? null : "fonts",
|
|
273
287
|
output,
|