@gentbajko/slopify 4.3.5 → 4.5.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/dist/edge/http/projects.js +4 -1
- package/dist/extension/slopify-studio-chrome.zip +0 -0
- package/dist/extension/slopify-studio-firefox.zip +0 -0
- package/dist/main.js +12 -3
- package/dist/patch-notes/4.4.0.md +37 -0
- package/dist/patch-notes/4.5.0.md +20 -0
- package/dist/patch-notes/index.json +12 -0
- package/dist/slices/admission/schema.js +3 -1
- package/dist/slices/rebuild/recipe-edit.js +8 -1
- package/dist/slices/rebuild/runtime-export.js +4 -3
- package/dist/slices/revisions/view.js +19 -8
- package/dist/slices/shorts/captions.js +2 -1
- package/dist/slices/storage/named-ids.js +46 -0
- package/dist/slices/storage/trim.js +24 -12
- package/dist/slices/subtitles/captions.js +2 -1
- package/dist/slices/video/cards.js +2 -0
- package/dist/slices/video/clip-cache.js +15 -7
- package/dist/slices/video/clip-captions.js +120 -0
- package/dist/slices/video/colour.js +22 -0
- package/dist/slices/video/edit-settings.js +17 -0
- package/dist/slices/video/encoder-probe.js +124 -0
- package/dist/slices/video/encoding.js +157 -92
- package/dist/slices/video/ffmpeg.js +64 -73
- package/dist/slices/video/look.js +23 -9
- package/dist/slices/video/move.js +89 -0
- package/dist/slices/video/pool.js +6 -5
- package/dist/slices/video/slideshow.js +137 -28
- package/dist/slices/video/still-sizes.js +37 -0
- package/dist/tutorials/Create-Video-and-Style.md +13 -0
- package/dist/tutorials/Settings-Reference.md +4 -2
- package/dist/tutorials/Video-Editing.md +4 -0
- package/dist/web/assets/index-hN_yzSRs.js +460 -0
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-Bvtq2QTE.js +0 -460
|
@@ -2,19 +2,15 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { isAbsolute, resolve as resolvePath } from "node:path";
|
|
3
3
|
import { errorText, internalError } from "../../kernel/errors.js";
|
|
4
4
|
import { bedChains, bedInputs } from "./ambient-mix.js";
|
|
5
|
-
import {
|
|
5
|
+
import { bt709Frames, bt709Scale } from "./colour.js";
|
|
6
|
+
import { codecArgs, copyTag, defaultEncode, setRenderPriority, } from "./encoding.js";
|
|
6
7
|
import { gradeFilter, lookChain, placed } from "./look.js";
|
|
7
|
-
import {
|
|
8
|
+
import { moveOf } from "./move.js";
|
|
9
|
+
import { decimal } from "./plan.js";
|
|
8
10
|
import { segments, transitionHalves } from "./transitions.js";
|
|
9
11
|
// Hand-rolled per the standards: the filtergraph is the load-bearing part of this slice
|
|
10
12
|
// and a wrapper would hide it. Every value goes into an argument array, never a shell
|
|
11
13
|
// string, so a title or a filename cannot become a command.
|
|
12
|
-
// zoompan works on a still that has been pre-scaled, because it steps the zoom in
|
|
13
|
-
// sub-pixel increments and a source at output resolution visibly jitters where the zoom is
|
|
14
|
-
// meant to be smooth and linear. A pan steps its crop window in whole source pixels, so
|
|
15
|
-
// the same four times gives it quarter-pixel steps on screen. Four times the frame is
|
|
16
|
-
// enough at 122.5%.
|
|
17
|
-
const prescale = 4;
|
|
18
14
|
const sampleRate = 44100;
|
|
19
15
|
const channelLayout = "stereo";
|
|
20
16
|
// `bundled` is ffmpeg-static's export. It is typed as unknown because the package is
|
|
@@ -80,11 +76,11 @@ function clipKey(edit, segment) {
|
|
|
80
76
|
: [shot?.source, shot?.motion, shot?.frames, segment.from, segment.count, at]);
|
|
81
77
|
}
|
|
82
78
|
// A whole shot as one clip.
|
|
83
|
-
export function clipArgs(frame, shot, output,
|
|
84
|
-
return segmentArgs({ ...frame, shots: [shot] }, { kind: "shot", shot: 0, from: 0, count: shot.frames, start: 0 }, output,
|
|
79
|
+
export function clipArgs(frame, shot, output, use = "watched") {
|
|
80
|
+
return segmentArgs({ ...frame, shots: [shot] }, { kind: "shot", shot: 0, from: 0, count: shot.frames, start: 0 }, output, use);
|
|
85
81
|
}
|
|
86
82
|
// One clip of the slideshow: part of a shot, or a transition between two, with the Look.
|
|
87
|
-
export function segmentArgs(edit, segment, output,
|
|
83
|
+
export function segmentArgs(edit, segment, output, use = "watched",
|
|
88
84
|
// The clip's own chapter-card script, beside it in the working folder (`cards.ts`).
|
|
89
85
|
cardsFile = "cards.ass",
|
|
90
86
|
// Settings → Production defaults → Rendering (`encoding.ts`).
|
|
@@ -95,12 +91,17 @@ encode = defaultEncode) {
|
|
|
95
91
|
if (shot === undefined)
|
|
96
92
|
throw new Error(internalError("the video's edit list lost a shot", "Press Make the video again in the project's Video section"));
|
|
97
93
|
const at = inputs.filter((one) => one === "-i").length;
|
|
98
|
-
const
|
|
94
|
+
const grade = gradeFilter(edit.look, shot.source.kind === "video" ? "video" : "still");
|
|
95
|
+
const built = pictureChain(edit, shot, from, segment.count, at, label, grade);
|
|
99
96
|
inputs.push(...built.inputs);
|
|
100
97
|
chains.push(built.chain);
|
|
101
98
|
};
|
|
102
|
-
const
|
|
103
|
-
|
|
99
|
+
const own = typeof use === "string" ? undefined : use;
|
|
100
|
+
// The last filter's output label, with the frames' colour tags set on the way out; a clip
|
|
101
|
+
// with its own captions hands its picture to them first.
|
|
102
|
+
const tagged = own === undefined ? `,${bt709Frames}[v]` : "[c]";
|
|
103
|
+
const look = lookChain(edit, segment.start, segment.count, "[p]", tagged, cardsFile);
|
|
104
|
+
const picked = look === undefined ? tagged : "[p]";
|
|
104
105
|
if (segment.kind === "shot")
|
|
105
106
|
picture(edit.shots[segment.shot], segment.from, picked);
|
|
106
107
|
else {
|
|
@@ -114,6 +115,14 @@ encode = defaultEncode) {
|
|
|
114
115
|
}
|
|
115
116
|
if (look !== undefined)
|
|
116
117
|
chains.push(look);
|
|
118
|
+
if (own !== undefined)
|
|
119
|
+
chains.push(...burnIn(inputs, own.portraits ?? [], {
|
|
120
|
+
from: "[c]",
|
|
121
|
+
// Drawn on the pixels the encoder is given, as captions over decoded clips are.
|
|
122
|
+
before: "format=yuv420p,",
|
|
123
|
+
script: own.script,
|
|
124
|
+
fonts: own.fonts,
|
|
125
|
+
}));
|
|
117
126
|
return [
|
|
118
127
|
...progressArgs,
|
|
119
128
|
...inputs,
|
|
@@ -125,7 +134,7 @@ encode = defaultEncode) {
|
|
|
125
134
|
...(segment.kind === "shot" && segment.from === 0 && look === undefined
|
|
126
135
|
? []
|
|
127
136
|
: ["-frames:v", String(segment.count)]),
|
|
128
|
-
...codecArgs(encode,
|
|
137
|
+
...codecArgs(encode, own !== undefined ? "captioned" : use === "recaptioned" ? "intermediate" : "final", edit.look),
|
|
129
138
|
"-an",
|
|
130
139
|
output,
|
|
131
140
|
];
|
|
@@ -160,24 +169,42 @@ function pictureChain(frame, shot, from, count, input, label, grade) {
|
|
|
160
169
|
`setpts=PTS-STARTPTS,fps=${String(fps)},format=yuv420p${label}`,
|
|
161
170
|
};
|
|
162
171
|
}
|
|
163
|
-
const move =
|
|
164
|
-
// A still that does not move has no sub-pixel steps to smooth, so it is not prescaled.
|
|
165
|
-
const factor = move === undefined ? 1 : prescale;
|
|
166
|
-
const wide = frame.width * factor;
|
|
167
|
-
const tall = frame.height * factor;
|
|
172
|
+
const move = moveOf(frame, shot.motion, shot.frames, frameExpression(from, count, shot.frames), frame.stills?.get(source.path));
|
|
168
173
|
// Clips that meet in a transition are brought to one pixel format first, since xfade
|
|
169
174
|
// refuses to blend two that differ; a plain shot is left as it always was.
|
|
170
175
|
const plain = from === 0 && count === shot.frames;
|
|
176
|
+
const still = `[${String(input)}:v]trim=end_frame=1,setpts=PTS-STARTPTS,` +
|
|
177
|
+
// The grade is applied here, to the one still frame, rather than to every frame after.
|
|
178
|
+
(grade === undefined ? "" : `${grade},`);
|
|
179
|
+
const out = `setsar=1${plain ? "" : ",format=yuv420p"}${label}`;
|
|
180
|
+
// zoompan turns the one still into the shot's frames either way: it is what ends the
|
|
181
|
+
// stream at exactly `count`.
|
|
182
|
+
if (move === undefined)
|
|
183
|
+
return {
|
|
184
|
+
inputs: ["-i", source.path],
|
|
185
|
+
chain: still +
|
|
186
|
+
// Cover the frame and centre-crop, never letterbox.
|
|
187
|
+
`scale=${frame.width}:${frame.height}:force_original_aspect_ratio=increase:${bt709Scale},` +
|
|
188
|
+
`crop=${frame.width}:${frame.height},` +
|
|
189
|
+
`zoompan=z='1':d=${count}:x='${centredX}':y='${centredY}':` +
|
|
190
|
+
`s=${frame.width}x${frame.height}:fps=${frame.fps},${out}`,
|
|
191
|
+
};
|
|
192
|
+
const { base, canvas } = move;
|
|
171
193
|
return {
|
|
172
194
|
inputs: ["-i", source.path],
|
|
173
|
-
chain:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
chain: still +
|
|
196
|
+
`scale=${base.width}:${base.height}:force_original_aspect_ratio=increase:flags=lanczos:${bt709Scale},` +
|
|
197
|
+
`crop=${base.width}:${base.height},` +
|
|
198
|
+
// A base under the frame sits top left of it, its last column and row drawn out to
|
|
199
|
+
// the frame's edges, so the sampler never reads black past the still.
|
|
200
|
+
(canvas.width > base.width
|
|
201
|
+
? `pad=${canvas.width}:${canvas.height}:0:0,` +
|
|
202
|
+
`fillborders=right=${canvas.width - base.width}:bottom=${canvas.height - base.height}:mode=smear,`
|
|
203
|
+
: "") +
|
|
204
|
+
`zoompan=z='1':d=${count}:x='0':y='0':s=${canvas.width}x${canvas.height}:fps=${frame.fps},` +
|
|
205
|
+
`perspective=${move.quad}:sense=source:eval=frame:interpolation=cubic,` +
|
|
206
|
+
(canvas.width > frame.width ? `crop=${frame.width}:${frame.height}:0:0,` : "") +
|
|
207
|
+
out,
|
|
181
208
|
};
|
|
182
209
|
}
|
|
183
210
|
// ceiling: a clip shorter than its shot is slowed to at most half speed, which still reads
|
|
@@ -190,7 +217,7 @@ export function slowdown(clip, shot) {
|
|
|
190
217
|
return "1";
|
|
191
218
|
return decimal(Math.round(Math.min(slowestSpeed, shot / clip) * 1000));
|
|
192
219
|
}
|
|
193
|
-
//
|
|
220
|
+
// A filter's `on` counts the clip's own frames from 0; a clip that starts `from` frames into
|
|
194
221
|
// its shot adds that, and one that reaches before or past the shot holds at its ends.
|
|
195
222
|
function frameExpression(from, count, frames) {
|
|
196
223
|
const shifted = from === 0 ? "on" : `(on${from > 0 ? "+" : "-"}${String(Math.abs(from))})`;
|
|
@@ -268,7 +295,9 @@ export function joinArgs(edit, output, list, burnSubtitles = false, portraits =
|
|
|
268
295
|
"-map",
|
|
269
296
|
burnSubtitles ? "[v]" : "0:v",
|
|
270
297
|
...(audio ? ["-map", sound === undefined ? "[a]" : "1:a"] : []),
|
|
271
|
-
...(burnSubtitles
|
|
298
|
+
...(burnSubtitles
|
|
299
|
+
? codecArgs(encode, "final", edit.look)
|
|
300
|
+
: ["-c:v", "copy", ...copyTag(encode)]),
|
|
272
301
|
...(audio ? ["-c:a", sound === undefined ? "aac" : "copy"] : ["-an"]),
|
|
273
302
|
"-movflags",
|
|
274
303
|
"+faststart",
|
|
@@ -288,7 +317,7 @@ export function burnPartArgs(edit, list, output, start, portraits = [], encode =
|
|
|
288
317
|
// back to 25 fps and drops frames.
|
|
289
318
|
after: `,setpts=PTS-STARTPTS,fps=${String(edit.fps)}`,
|
|
290
319
|
};
|
|
291
|
-
const chains = burnIn(inputs, portraits, shifted
|
|
320
|
+
const chains = burnIn(inputs, portraits, shifted);
|
|
292
321
|
return [
|
|
293
322
|
...progressArgs,
|
|
294
323
|
...inputs,
|
|
@@ -305,18 +334,18 @@ export function burnPartArgs(edit, list, output, start, portraits = [], encode =
|
|
|
305
334
|
// input and under the captions, so the panel's lit outline is drawn over them; a video without
|
|
306
335
|
// any is burned exactly as before. A still image is one frame, which overlay holds to the end
|
|
307
336
|
// (`eof_action=repeat`).
|
|
308
|
-
function burnIn(inputs, portraits,
|
|
337
|
+
function burnIn(inputs, portraits, draw = {}) {
|
|
309
338
|
let first = inputs.filter((value) => value === "-i").length;
|
|
310
|
-
let source = "[0:v]";
|
|
339
|
+
let source = draw.from ?? "[0:v]";
|
|
311
340
|
const video = [];
|
|
312
341
|
portraits.forEach((portrait, at) => {
|
|
313
342
|
inputs.push("-i", portrait.path);
|
|
314
343
|
const size = String(portrait.size);
|
|
315
|
-
video.push(`[${String(first)}:v]scale=${size}:${size}:force_original_aspect_ratio=increase,crop=${size}:${size},setsar=1[pic${String(at)}]`, `${source}[pic${String(at)}]overlay=x=${String(portrait.x)}:y=${String(portrait.y)}:eof_action=repeat[panel${String(at)}]`);
|
|
344
|
+
video.push(`[${String(first)}:v]scale=${size}:${size}:force_original_aspect_ratio=increase:${bt709Scale},crop=${size}:${size},setsar=1[pic${String(at)}]`, `${source}[pic${String(at)}]overlay=x=${String(portrait.x)}:y=${String(portrait.y)}:eof_action=repeat[panel${String(at)}]`);
|
|
316
345
|
source = `[panel${String(at)}]`;
|
|
317
346
|
first += 1;
|
|
318
347
|
});
|
|
319
|
-
video.push(`${source}${before}ass=filename
|
|
348
|
+
video.push(`${source}${draw.before ?? ""}ass=filename=${draw.script ?? "subtitles.ass"}:fontsdir=${draw.fonts ?? "fonts"}${draw.after ?? ""},${bt709Frames}[v]`);
|
|
320
349
|
return video;
|
|
321
350
|
}
|
|
322
351
|
const progressArgs = [
|
|
@@ -332,44 +361,6 @@ const progressArgs = [
|
|
|
332
361
|
];
|
|
333
362
|
const centredX = "iw/2-(iw/zoom/2)";
|
|
334
363
|
const centredY = "ih/2-(ih/zoom/2)";
|
|
335
|
-
// zoompan's expressions for a motion, or undefined for one that does not move. `on` is
|
|
336
|
-
// zoompan's output frame counter, 0 to d-1 (`at` shifts it for part of a shot), and a
|
|
337
|
-
// one-frame shot has no span to divide by, so it holds where it starts. `zoom` in x and y is
|
|
338
|
-
// the current zoom, so iw-iw/zoom is the room the crop window has to travel in.
|
|
339
|
-
function zoompan(motion, frames, at = "on") {
|
|
340
|
-
if (motion.kind === "still")
|
|
341
|
-
return undefined;
|
|
342
|
-
const range = zoomRange(motion.percent);
|
|
343
|
-
if (range === undefined)
|
|
344
|
-
return undefined;
|
|
345
|
-
const span = frames - 1;
|
|
346
|
-
if (motion.kind === "zoom") {
|
|
347
|
-
// Zoom in rises from 100%, zoom out falls back to it, linear over the shot.
|
|
348
|
-
const z = motion.direction === "in"
|
|
349
|
-
? span < 1
|
|
350
|
-
? range.from
|
|
351
|
-
: `${range.from}+${range.by}*${at}/${span}`
|
|
352
|
-
: span < 1
|
|
353
|
-
? range.to
|
|
354
|
-
: `${range.to}-${range.by}*${at}/${span}`;
|
|
355
|
-
return { z, x: centredX, y: centredY };
|
|
356
|
-
}
|
|
357
|
-
return {
|
|
358
|
-
z: range.to,
|
|
359
|
-
x: `(iw-iw/zoom)*(${travel(motion.from.x, motion.to.x, span, at)})`,
|
|
360
|
-
y: `(ih-ih/zoom)*(${travel(motion.from.y, motion.to.y, span, at)})`,
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
// A share of the room from `from` to `to`, linear over the shot. Built in whole
|
|
364
|
-
// thousandths as decimal text, like the zoom, so 1 - 0.5 reads 0.5 and never
|
|
365
|
-
// 0.49999999999999994.
|
|
366
|
-
function travel(from, to, span, at) {
|
|
367
|
-
const start = Math.round(from * 1000);
|
|
368
|
-
const by = Math.round(to * 1000) - start;
|
|
369
|
-
if (span < 1 || by === 0)
|
|
370
|
-
return decimal(start);
|
|
371
|
-
return `${decimal(start)}${by > 0 ? "+" : "-"}${decimal(Math.abs(by))}*${at}/${span}`;
|
|
372
|
-
}
|
|
373
364
|
function seconds(value) {
|
|
374
365
|
return value.toFixed(3);
|
|
375
366
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bt709Scale } from "./colour.js";
|
|
1
2
|
// The Look: filters appended to each clip's picture before it is encoded, so they cost one
|
|
2
3
|
// pass over frames that are being made anyway and the render stays clip by clip. Everything
|
|
3
4
|
// is ffmpeg's own filters with fixed numbers: no footage, no LUT files, and the same project
|
|
@@ -25,20 +26,33 @@ const grainStrength = {
|
|
|
25
26
|
export function lookEncoding(look) {
|
|
26
27
|
return look !== undefined && look.grain !== "off" ? ["-tune", "grain"] : [];
|
|
27
28
|
}
|
|
29
|
+
// Each grade's filters on RGB, then on YUV.
|
|
28
30
|
const grades = {
|
|
29
31
|
// Golden highlights, a touch of amber in the mids, cooler shadows kept for depth.
|
|
30
|
-
warm:
|
|
31
|
-
"
|
|
32
|
+
warm: {
|
|
33
|
+
rgb: "colorbalance=rs=0.02:bs=0.04:rm=0.08:gm=0.02:bm=-0.07:rh=0.07:gh=0.03:bh=-0.08",
|
|
34
|
+
yuv: "eq=saturation=1.12:contrast=1.04",
|
|
35
|
+
},
|
|
32
36
|
// Blue-green shadows and mids, highlights barely touched.
|
|
33
|
-
cold:
|
|
34
|
-
|
|
37
|
+
cold: {
|
|
38
|
+
rgb: "colorbalance=rs=-0.06:bs=0.08:rm=-0.05:gm=0.01:bm=0.06:rh=-0.02:bh=0.03",
|
|
39
|
+
yuv: "eq=saturation=0.9",
|
|
40
|
+
},
|
|
41
|
+
desaturated: { yuv: "eq=saturation=0.55:contrast=1.06" },
|
|
35
42
|
// The classic sepia matrix.
|
|
36
|
-
sepia:
|
|
43
|
+
sepia: {
|
|
44
|
+
rgb: "colorchannelmixer=rr=0.393:rg=0.769:rb=0.189:gr=0.349:gg=0.686:gb=0.168:br=0.272:bg=0.534:bb=0.131",
|
|
45
|
+
},
|
|
37
46
|
};
|
|
38
47
|
// The grade as a filter for a picture's source, or undefined for none: a still is graded once,
|
|
39
|
-
// a clip frame by frame.
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
// a clip frame by frame. A still is RGB, so its one step into YUV is made here as BT.709 rather
|
|
49
|
+
// than left to ffmpeg's BT.601 default; a clip's YUV is left as it is.
|
|
50
|
+
export function gradeFilter(look, source) {
|
|
51
|
+
if (look === undefined || look.grade === "none")
|
|
52
|
+
return undefined;
|
|
53
|
+
const { rgb, yuv } = grades[look.grade];
|
|
54
|
+
const toYuv = source === "still" && yuv !== undefined ? `scale=${bt709Scale},format=yuv444p` : undefined;
|
|
55
|
+
return [rgb, toYuv, yuv].filter((step) => step !== undefined).join(",");
|
|
42
56
|
}
|
|
43
57
|
export function hasLook(look) {
|
|
44
58
|
return (look !== undefined &&
|
|
@@ -135,7 +149,7 @@ function atmosphereSource(frame, atmosphere, start) {
|
|
|
135
149
|
const peak = "max(r(X,Y),max(g(X,Y),b(X,Y)))";
|
|
136
150
|
const lit = (plane) => `if(gt(${peak},0),255*${plane}(X,Y)/${peak},0)`;
|
|
137
151
|
const light = `format=gbrap,geq=r='${lit("r")}':g='${lit("g")}':b='${lit("b")}':` +
|
|
138
|
-
`a='${peak}*${atmosphereOpacity[atmosphere]}',format=yuva420p`;
|
|
152
|
+
`a='${peak}*${atmosphereOpacity[atmosphere]}',scale=${bt709Scale},format=yuva420p`;
|
|
139
153
|
const moving = (h, v) => `${light},loop=loop=-1:size=1,setpts=N/(${String(fps)}*TB),` +
|
|
140
154
|
`scroll=h=${String(h)}:v=${String(v)}:hpos=${position(h, start)}:vpos=${position(v, start)}`;
|
|
141
155
|
if (atmosphere === "embers")
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { decimal, zoomRange } from "./plan.js";
|
|
2
|
+
// How a still moves. Each frame shows a window of the still: a zoom shrinks it about the
|
|
3
|
+
// centre, a pan slides it across the room the zoom leaves. `perspective` reads that window
|
|
4
|
+
// between whole pixels, so a move of a fraction of a pixel a frame advances by that fraction.
|
|
5
|
+
//
|
|
6
|
+
// zoompan, which did this before, can only land the window on a whole source pixel, and on
|
|
7
|
+
// every second one once the picture is 4:2:0 as the encoder asks. On a still enlarged four
|
|
8
|
+
// times that is a step of 0.61 of a frame pixel: a pan of 0.46 a frame stood still and jumped
|
|
9
|
+
// in turn, and a zoom's centre wandered by 0.45. Enlarging further costs the square of the
|
|
10
|
+
// factor and only halves the step.
|
|
11
|
+
//
|
|
12
|
+
// A sampler that interpolates is sharpest where a frame pixel lands on a source pixel and
|
|
13
|
+
// softer between. Where it reads the still at close to one to one, those places form wide
|
|
14
|
+
// bands that drift as the shot moves, and fine detail breathes: with the still at the frame's
|
|
15
|
+
// own size, the start of a zoom measured four and a half times zoompan's change in fine detail
|
|
16
|
+
// from frame to frame. So the still is first brought, once, to a base that keeps the sampler
|
|
17
|
+
// clear of one to one for the whole shot: under the frame for a still with no more pixels
|
|
18
|
+
// than that base holds, so it is only ever enlarged, and above the shot's whole zoom for any
|
|
19
|
+
// other, so it is only ever reduced and keeps the detail a larger still has. Both measured at
|
|
20
|
+
// or under zoompan's own change.
|
|
21
|
+
const smallShare = 0.92;
|
|
22
|
+
const clearOfOne = 1.05;
|
|
23
|
+
// The move of a shot, or undefined for one that does not move. `at` is the shot's frame as
|
|
24
|
+
// the filter counts it, 0 to frames-1; a one-frame shot has no span to divide by and holds
|
|
25
|
+
// where it starts.
|
|
26
|
+
export function moveOf(frame, motion, frames, at, still) {
|
|
27
|
+
if (motion.kind === "still")
|
|
28
|
+
return undefined;
|
|
29
|
+
const range = zoomRange(motion.percent);
|
|
30
|
+
if (range === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
const small = shaped(frame, smallShare, -1);
|
|
33
|
+
// What the frame shows of the still is the still cropped to the frame's shape.
|
|
34
|
+
const fits = still !== undefined &&
|
|
35
|
+
Math.min(still.width, (still.height * frame.width) / frame.height) <= small.width;
|
|
36
|
+
const base = fits ? small : shaped(frame, clearOfOne * Number(range.to), 1);
|
|
37
|
+
const canvas = fits ? { width: frame.width, height: frame.height } : base;
|
|
38
|
+
const span = frames - 1;
|
|
39
|
+
const zoom = motion.kind === "pan"
|
|
40
|
+
? range.to
|
|
41
|
+
: span < 1
|
|
42
|
+
? motion.direction === "in"
|
|
43
|
+
? range.from
|
|
44
|
+
: range.to
|
|
45
|
+
: motion.direction === "in"
|
|
46
|
+
? `(${range.from}+${range.by}*${at}/${String(span)})`
|
|
47
|
+
: `(${range.to}-${range.by}*${at}/${String(span)})`;
|
|
48
|
+
// The window is the base over the zoom, so this is the room it has to travel in.
|
|
49
|
+
const room = (side) => `(${String(side)}-${String(side)}/${zoom})`;
|
|
50
|
+
const x = motion.kind === "pan"
|
|
51
|
+
? `${room(base.width)}*(${travel(motion.from.x, motion.to.x, span, at)})`
|
|
52
|
+
: `${room(base.width)}/2`;
|
|
53
|
+
const y = motion.kind === "pan"
|
|
54
|
+
? `${room(base.height)}*(${travel(motion.from.y, motion.to.y, span, at)})`
|
|
55
|
+
: `${room(base.height)}/2`;
|
|
56
|
+
// The corners are where the canvas's own corners read from, and the window is to fill the
|
|
57
|
+
// frame: on a canvas larger than the frame they lie that much further out.
|
|
58
|
+
const reach = (side, whole, shown) => `${String(side)}/${zoom}${whole === shown ? "" : `*${String(whole)}/${String(shown)}`}`;
|
|
59
|
+
const right = `${x}+${reach(base.width, canvas.width, frame.width)}`;
|
|
60
|
+
const bottom = `${y}+${reach(base.height, canvas.height, frame.height)}`;
|
|
61
|
+
return {
|
|
62
|
+
base,
|
|
63
|
+
canvas,
|
|
64
|
+
quad: `x0='${x}':y0='${y}':x1='${right}':y1='${y}':x2='${x}':y2='${bottom}':x3='${right}':y3='${bottom}'`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// The size nearest `share` of the frame that keeps the frame's exact shape with both sides
|
|
68
|
+
// even, as 4:2:0 needs: under it when `step` is -1, over it when 1.
|
|
69
|
+
function shaped(frame, share, step) {
|
|
70
|
+
const unit = divisor(frame.width, frame.height);
|
|
71
|
+
const across = frame.width / unit;
|
|
72
|
+
const down = frame.height / unit;
|
|
73
|
+
let units = Math.max(1, step === -1 ? Math.floor(share * unit) : Math.ceil(share * unit));
|
|
74
|
+
while ((across * units) % 2 !== 0 || (down * units) % 2 !== 0)
|
|
75
|
+
units += units === 1 ? 1 : step;
|
|
76
|
+
return { width: across * units, height: down * units };
|
|
77
|
+
}
|
|
78
|
+
function divisor(a, b) {
|
|
79
|
+
return b === 0 ? a : divisor(b, a % b);
|
|
80
|
+
}
|
|
81
|
+
// A share of the room from `from` to `to`, linear over the shot. Built in whole thousandths
|
|
82
|
+
// as decimal text, like the zoom, so 1 - 0.5 reads 0.5 and never 0.49999999999999994.
|
|
83
|
+
function travel(from, to, span, at) {
|
|
84
|
+
const start = Math.round(from * 1000);
|
|
85
|
+
const by = Math.round(to * 1000) - start;
|
|
86
|
+
if (span < 1 || by === 0)
|
|
87
|
+
return decimal(start);
|
|
88
|
+
return `${decimal(start)}${by > 0 ? "+" : "-"}${decimal(Math.abs(by))}*${at}/${String(span)}`;
|
|
89
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { availableParallelism, totalmem } from "node:os";
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
2
|
+
// One clip's run does not fill the machine, so several go at once. Measured on 32 threads
|
|
3
|
+
// with ffmpeg 7, on the first 24 shots of a real project (11.5 minutes of video, captions
|
|
4
|
+
// burned in): one at a time 215 s, two 156 s, four 141 s, eight 141 s, twelve 142 s. The
|
|
5
|
+
// sampler and x264 both use several cores, so past four the machine is simply full, and eight
|
|
6
|
+
// costs nothing more. Each run holds about 1 GB, most of it x264's own frames, so the memory
|
|
7
|
+
// the process may use caps it as well.
|
|
7
8
|
const mostJobs = 8;
|
|
8
9
|
const coresPerJob = 4;
|
|
9
10
|
const bytesPerJob = 3 * 1024 ** 3;
|