@gentbajko/slopify 4.3.4 → 4.4.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/edge/http/settings.js +2 -0
- package/dist/extension/slopify-studio-chrome.zip +0 -0
- package/dist/extension/slopify-studio-firefox.zip +0 -0
- package/dist/main.js +8 -1
- package/dist/patch-notes/4.3.5.md +30 -0
- package/dist/patch-notes/4.4.0.md +37 -0
- package/dist/patch-notes/index.json +12 -0
- package/dist/slices/rebuild/runtime-export-short.js +4 -2
- package/dist/slices/rebuild/runtime-export.js +5 -2
- package/dist/slices/rebuild/runtime-provider.js +14 -0
- package/dist/slices/revisions/view.js +19 -8
- package/dist/slices/settings/model.js +1 -0
- package/dist/slices/settings/playback.js +11 -1
- 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/studio/videos.js +20 -6
- 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/encoding.js +23 -5
- package/dist/slices/video/ffmpeg.js +60 -71
- package/dist/slices/video/look.js +23 -9
- package/dist/slices/video/move.js +89 -0
- package/dist/slices/video/plan.js +58 -11
- package/dist/slices/video/pool.js +6 -5
- package/dist/slices/video/render-gate.js +45 -0
- package/dist/slices/video/slideshow.js +105 -20
- package/dist/slices/video/still-sizes.js +37 -0
- package/dist/tutorials/Settings-Reference.md +2 -2
- package/dist/web/assets/{index-BwKV_9F3.js → index-CA_I2trg.js} +160 -160
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
|
@@ -55,18 +55,20 @@ export function planRender(input) {
|
|
|
55
55
|
const totalFrames = Math.max(1, Math.round(totalSeconds * fps));
|
|
56
56
|
const edit = input.edit;
|
|
57
57
|
const narration = input.body === undefined ? undefined : edit?.narration;
|
|
58
|
+
const figures = figureFrames(edit?.figures ?? [], totalFrames);
|
|
59
|
+
const figureTotal = figures.reduce((sum, figure) => sum + figure.frames, 0);
|
|
60
|
+
const shotSeconds = holdSeconds(input, Math.max(0, totalFrames - figureTotal) / fps);
|
|
58
61
|
const lengthsFor = (from, frameCount) => narration === undefined
|
|
59
|
-
? everyLengths(Math.max(1, Math.round(
|
|
62
|
+
? everyLengths(Math.max(1, Math.round(shotSeconds * fps)), frameCount)
|
|
60
63
|
: narrationShotFrames({
|
|
61
64
|
totalFrames: frameCount,
|
|
62
65
|
fps,
|
|
63
|
-
imageSeconds:
|
|
66
|
+
imageSeconds: shotSeconds,
|
|
64
67
|
cutPoints: narration.cutPoints.map((point) => point - from / fps),
|
|
65
68
|
chapterStarts: narration.chapterStarts
|
|
66
69
|
.map((start) => start - from / fps)
|
|
67
70
|
.filter((start) => start >= 0 && start < frameCount / fps),
|
|
68
71
|
});
|
|
69
|
-
const figures = figureFrames(edit?.figures ?? [], totalFrames);
|
|
70
72
|
const planned = figures.length === 0
|
|
71
73
|
? shots(input, lengthsFor(0, totalFrames))
|
|
72
74
|
: aroundFigures(input, figures, totalFrames, lengthsFor);
|
|
@@ -77,7 +79,7 @@ export function planRender(input) {
|
|
|
77
79
|
return {
|
|
78
80
|
gapSeconds: input.gapSeconds,
|
|
79
81
|
edgeSeconds: input.edgeSeconds,
|
|
80
|
-
imageSeconds:
|
|
82
|
+
imageSeconds: shotSeconds,
|
|
81
83
|
zoomPercent: input.zoomPercent,
|
|
82
84
|
motionStyle: input.motionStyle,
|
|
83
85
|
editList: {
|
|
@@ -202,18 +204,53 @@ export function audioTimeline(input, minimumGap = 1 / fps) {
|
|
|
202
204
|
}
|
|
203
205
|
// Every N seconds: each shot `each` frames until the timeline is full; the last shot is cut
|
|
204
206
|
// to what is left. A timeline shorter than one shot is a single shot.
|
|
207
|
+
// How long one image stays on screen. Each image is made for one moment of the narration, so
|
|
208
|
+
// the shot length follows how many images there are rather than a fixed setting: Seconds per
|
|
209
|
+
// image on its own decides the shot count and then replays the set to fill the timeline, which
|
|
210
|
+
// at 240 images over two and a half hours played the whole set through two and a half times and
|
|
211
|
+
// brought the opening illustrations back over the closing chapters. Seconds per image stays the
|
|
212
|
+
// floor, so a project never cuts faster than it asked for, and `maxHoldSeconds` the ceiling, so
|
|
213
|
+
// a handful of images over a long narration still cuts, and moves, rather than holding one
|
|
214
|
+
// frame for a quarter of an hour. A silent video already shows every image once, and a short's
|
|
215
|
+
// images are counted from Seconds per image to begin with (`shortImageCount`), so both come out
|
|
216
|
+
// unchanged.
|
|
217
|
+
const maxHoldSeconds = 120;
|
|
218
|
+
function holdSeconds(input, fillSeconds) {
|
|
219
|
+
// One image has no order to follow, so it keeps its own slots and the motion that alternates
|
|
220
|
+
// across them rather than becoming a single still held for the whole narration.
|
|
221
|
+
if (input.body === undefined || input.images.length < 2)
|
|
222
|
+
return input.imageSeconds;
|
|
223
|
+
const share = fillSeconds / input.images.length;
|
|
224
|
+
if (!Number.isFinite(share) || share <= 0)
|
|
225
|
+
return input.imageSeconds;
|
|
226
|
+
// Past this, one image would sit on screen for minutes on end. The shots stay at the pace the
|
|
227
|
+
// project asked for, so the motion keeps refreshing across a long hold (`motion.ts`); the
|
|
228
|
+
// images still go in order, one after another, and none of them comes round twice.
|
|
229
|
+
if (share > maxHoldSeconds)
|
|
230
|
+
return input.imageSeconds;
|
|
231
|
+
return Math.max(input.imageSeconds, share);
|
|
232
|
+
}
|
|
233
|
+
// Which image a shot shows: the images in order, spread evenly over the shots. More shots than
|
|
234
|
+
// images holds a few of them over two shots in a row rather than starting the set over, and
|
|
235
|
+
// more images than shots leaves some out rather than dropping the whole tail of the set.
|
|
236
|
+
function imageAt(at, total, images) {
|
|
237
|
+
if (images <= 0 || total <= 0)
|
|
238
|
+
return 0;
|
|
239
|
+
return Math.min(images - 1, Math.floor((at * images) / total));
|
|
240
|
+
}
|
|
205
241
|
function everyLengths(each, totalFrames) {
|
|
206
242
|
const count = Math.ceil(totalFrames / each);
|
|
207
243
|
return Array.from({ length: count }, (_value, at) => Math.min(each, totalFrames - each * at));
|
|
208
244
|
}
|
|
209
|
-
// The images
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
|
|
245
|
+
// The images in order, one per shot, spread over the whole timeline (`imageAt`). The motion
|
|
246
|
+
// goes by the shot's place, not the image (`motion.ts`), so an image held over two shots may
|
|
247
|
+
// move another way in the second. A moving clip in an image's place plays as it is, with no
|
|
248
|
+
// motion of its own. `total` is every shot in the timeline, not just this stretch of it, so
|
|
249
|
+
// the figures do not restart the set.
|
|
250
|
+
function shots(input, lengths, first = 0, total = lengths.length) {
|
|
214
251
|
return lengths.map((frames, place) => {
|
|
215
252
|
const at = first + place;
|
|
216
|
-
const index = at
|
|
253
|
+
const index = imageAt(at, total, input.images.length);
|
|
217
254
|
const clip = input.edit?.clips?.[index];
|
|
218
255
|
return clip === undefined
|
|
219
256
|
? {
|
|
@@ -252,6 +289,16 @@ export function figureFrames(figures, totalFrames) {
|
|
|
252
289
|
// whole video of that length, and keep counting across them so no image or motion repeats
|
|
253
290
|
// where a card interrupts. Each card is shown still, whole.
|
|
254
291
|
function aroundFigures(input, figures, totalFrames, lengthsFor) {
|
|
292
|
+
const lengthsAt = (from, to) => to > from ? lengthsFor(from, to - from) : [];
|
|
293
|
+
// Every stretch is measured before any image is placed, so the images spread over all of
|
|
294
|
+
// them together rather than starting the set over after each figure.
|
|
295
|
+
let total = 0;
|
|
296
|
+
let measured = 0;
|
|
297
|
+
for (const figure of figures) {
|
|
298
|
+
total += lengthsAt(measured, figure.startFrame).length;
|
|
299
|
+
measured = figure.startFrame + figure.frames;
|
|
300
|
+
}
|
|
301
|
+
total += lengthsAt(measured, totalFrames).length;
|
|
255
302
|
const out = [];
|
|
256
303
|
let cursor = 0;
|
|
257
304
|
let slot = 0;
|
|
@@ -259,7 +306,7 @@ function aroundFigures(input, figures, totalFrames, lengthsFor) {
|
|
|
259
306
|
if (to <= cursor)
|
|
260
307
|
return;
|
|
261
308
|
const lengths = lengthsFor(cursor, to - cursor);
|
|
262
|
-
out.push(...shots(input, lengths, slot));
|
|
309
|
+
out.push(...shots(input, lengths, slot, total));
|
|
263
310
|
slot += lengths.length;
|
|
264
311
|
cursor = to;
|
|
265
312
|
};
|
|
@@ -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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// How many videos this computer renders at once (Settings → Production defaults → Videos
|
|
2
|
+
// rendered at once). A render decodes the whole picture track and encodes hours of it, so two
|
|
3
|
+
// at once cost more than twice one: they share the processor, the disk and the memory, and
|
|
4
|
+
// enough of them together leave the app with too little of each to answer the page.
|
|
5
|
+
//
|
|
6
|
+
// A render holds a place for as long as it runs; the rest wait their turn rather than being
|
|
7
|
+
// refused, so a waiting render still finishes, only later. The limit is read each time a place
|
|
8
|
+
// is asked for and each time one is given back, so raising it in Settings lets a waiting render
|
|
9
|
+
// start without a restart, and lowering it takes effect as the renders running now finish.
|
|
10
|
+
import { videoRenderConcurrencyMax } from "./encoding.js";
|
|
11
|
+
export function createRenderGate(limit) {
|
|
12
|
+
const waiting = [];
|
|
13
|
+
let active = 0;
|
|
14
|
+
// A hand-edited setting cannot make the gate let everything through, or nothing.
|
|
15
|
+
const allowed = () => {
|
|
16
|
+
const asked = Math.floor(limit());
|
|
17
|
+
return Number.isFinite(asked) ? Math.max(1, Math.min(videoRenderConcurrencyMax, asked)) : 1;
|
|
18
|
+
};
|
|
19
|
+
const drain = () => {
|
|
20
|
+
while (active < allowed()) {
|
|
21
|
+
const next = waiting.shift();
|
|
22
|
+
if (next === undefined)
|
|
23
|
+
return;
|
|
24
|
+
active++;
|
|
25
|
+
next();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
hold: async (work) => {
|
|
30
|
+
if (active < allowed())
|
|
31
|
+
active++;
|
|
32
|
+
else
|
|
33
|
+
await new Promise((resolve) => waiting.push(resolve));
|
|
34
|
+
try {
|
|
35
|
+
return await work();
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
active--;
|
|
39
|
+
drain();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// The renders of a run that has no gate (a test, or an older wiring) go straight through.
|
|
45
|
+
export const openRenderGate = { hold: (work) => work() };
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { extname, join } from "node:path";
|
|
1
|
+
import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { extname, join, resolve } from "node:path";
|
|
3
3
|
import { errorText, internalError } from "../../kernel/errors.js";
|
|
4
4
|
import { masterFile, masterReport } from "../loudness/loudnorm.js";
|
|
5
5
|
import { cardsAss } from "./cards.js";
|
|
6
|
-
import { cacheKey, fileIdentity, keepClip, pruneClips, reuseClip } from "./clip-cache.js";
|
|
6
|
+
import { cacheKey, contentIdentity, fileIdentity, keepClip, pruneClips, reuseClip, } from "./clip-cache.js";
|
|
7
|
+
import { captionedClips, drawsOwnCaptions, readCaptions, } from "./clip-captions.js";
|
|
7
8
|
import { defaultEncode, nvencFallbackNotice, } from "./encoding.js";
|
|
8
9
|
import { audioMixArgs, burnPartArgs, concatList, joinArgs, runFfmpeg, segmentArgs, slideshowClips, } from "./ffmpeg.js";
|
|
9
10
|
import { cardsIn } from "./look.js";
|
|
10
11
|
import { inPool, renderJobs } from "./pool.js";
|
|
11
|
-
|
|
12
|
+
import { stillSizes } from "./still-sizes.js";
|
|
13
|
+
// estimate: a frame sampled from its still and encoded costs several plain encoded frames, and a
|
|
12
14
|
// copying join is nearly free, so progress is weighted by that rather than by clock time.
|
|
13
15
|
const clipWeight = 4;
|
|
14
16
|
const copyWeight = 0.05;
|
|
17
|
+
// The caption fonts beside the clips, apart from the chapter cards' `fonts`.
|
|
18
|
+
const captionFonts = "caption-fonts";
|
|
15
19
|
// floor: a burned-in part shorter than a minute is not worth its own run.
|
|
16
20
|
const leastPartFrames = 60 * 30;
|
|
17
21
|
// The sound the join plays, as the join itself brings every segment to it.
|
|
@@ -41,16 +45,26 @@ async function renderWith(run, encode) {
|
|
|
41
45
|
const priority = run.machine?.priority;
|
|
42
46
|
// The ffmpeg that encodes the picture; copying, sound and probing stay with the bundled one.
|
|
43
47
|
const encoder = encode.kind === "nvenc" ? encode.bin : run.bin;
|
|
44
|
-
const
|
|
48
|
+
const distinct = slideshowClips(edit);
|
|
49
|
+
// Captions are burned in one of two ways (`clip-captions.ts`): drawn by each clip's own run,
|
|
50
|
+
// or over the joined clips in a second encode.
|
|
51
|
+
const own = run.burnSubtitles && drawsOwnCaptions(distinct.clips, distinct.order)
|
|
52
|
+
? ownCaptions(run, edit.fps)
|
|
53
|
+
: undefined;
|
|
54
|
+
const twice = run.burnSubtitles && own === undefined;
|
|
55
|
+
const { clips, order, } = own === undefined
|
|
56
|
+
? { clips: distinct.clips.map((clip) => ({ name: clip.name, clip })), order: distinct.order }
|
|
57
|
+
: captionedClips(distinct.clips, distinct.order, own.captions, edit.fps);
|
|
58
|
+
const sized = { ...edit, stills: stillSizes(edit.shots, run.log) };
|
|
45
59
|
const msOf = (frames) => (frames / edit.fps) * 1000;
|
|
46
60
|
const joinMs = msOf(edit.shots.reduce((sum, shot) => sum + shot.frames, 0));
|
|
47
61
|
// Progress is reported against the video's length, the longer of picture and sound.
|
|
48
62
|
const totalMs = Math.max(joinMs, edit.audio.reduce((sum, segment) => sum + segment.seconds * 1000, 0));
|
|
49
|
-
const clipMs = clips.reduce((sum,
|
|
63
|
+
const clipMs = clips.reduce((sum, one) => sum + msOf(one.clip.frames), 0);
|
|
50
64
|
const jobs = run.jobs ?? renderJobs();
|
|
51
|
-
const parts =
|
|
65
|
+
const parts = twice ? burnParts(order, distinct.clips, jobs) : [];
|
|
52
66
|
const work = clipMs * clipWeight +
|
|
53
|
-
joinMs * (
|
|
67
|
+
joinMs * (twice ? 1 : copyWeight) +
|
|
54
68
|
(parts.length > 1 ? joinMs * copyWeight : 0);
|
|
55
69
|
const report = (done) => {
|
|
56
70
|
run.onProgress(work > 0 ? Math.round((Math.min(done, work) / work) * totalMs) : 0);
|
|
@@ -66,6 +80,8 @@ async function renderWith(run, encode) {
|
|
|
66
80
|
mkdirSync(join(workspace, "fonts"), { mode: 0o700 });
|
|
67
81
|
copyFileSync(font.path, join(workspace, "fonts", `card${extname(font.path)}`));
|
|
68
82
|
}
|
|
83
|
+
// And so are a clip's own captions, with their fonts and the speaker portraits.
|
|
84
|
+
const drawn = own === undefined ? undefined : captionFiles(own, run.portraits, workspace);
|
|
69
85
|
// The sound is mixed, levelled and encoded while the picture renders, on its own run; the
|
|
70
86
|
// join then only copies it in. Either failing stops the other, and the first failure is
|
|
71
87
|
// the one reported.
|
|
@@ -96,16 +112,25 @@ async function renderWith(run, encode) {
|
|
|
96
112
|
const tell = () => {
|
|
97
113
|
report(rendered + [...running.values()].reduce((sum, one) => sum + one, 0));
|
|
98
114
|
};
|
|
99
|
-
await inPool(clips, jobs, halt, async (
|
|
100
|
-
const
|
|
115
|
+
await inPool(clips, jobs, halt, async (made, signal) => {
|
|
116
|
+
const { clip } = made;
|
|
117
|
+
const script = made.name.replace(/\.mp4$/, ".ass");
|
|
101
118
|
const shown = cardsIn(cards, clip.segment.start, clip.segment.count);
|
|
102
|
-
const
|
|
119
|
+
const carded = shown.length > 0 && font !== undefined
|
|
103
120
|
? cardsAss(edit, shown, font.name, clip.segment.start, edit.cardColor)
|
|
104
121
|
: undefined;
|
|
105
|
-
if (
|
|
106
|
-
writeFileSync(join(workspace, script),
|
|
107
|
-
const
|
|
108
|
-
const
|
|
122
|
+
if (carded !== undefined)
|
|
123
|
+
writeFileSync(join(workspace, script), carded, { mode: 0o600 });
|
|
124
|
+
const spoken = made.name.replace(/\.mp4$/, ".said.ass");
|
|
125
|
+
const said = drawn === undefined ? undefined : made.said;
|
|
126
|
+
if (said !== undefined)
|
|
127
|
+
writeFileSync(join(workspace, spoken), said, { mode: 0o600 });
|
|
128
|
+
const output = join(workspace, made.name);
|
|
129
|
+
const args = segmentArgs(sized, clip.segment, output, drawn !== undefined && said !== undefined
|
|
130
|
+
? { script: spoken, fonts: drawn.fonts, portraits: drawn.portraits }
|
|
131
|
+
: twice
|
|
132
|
+
? "recaptioned"
|
|
133
|
+
: "watched", script, encode);
|
|
109
134
|
const weight = msOf(clip.frames) * clipWeight;
|
|
110
135
|
const cache = run.cache;
|
|
111
136
|
let key;
|
|
@@ -113,7 +138,18 @@ async function renderWith(run, encode) {
|
|
|
113
138
|
// let it go a moment ago) is encoded as if there were none.
|
|
114
139
|
try {
|
|
115
140
|
if (cache !== undefined) {
|
|
116
|
-
key = cacheKey(encoder,
|
|
141
|
+
key = cacheKey(encoder,
|
|
142
|
+
// The scripts are named after the clip's place in this render; what they say
|
|
143
|
+
// is in the key instead.
|
|
144
|
+
args.map((value) => {
|
|
145
|
+
const unsaid = said === undefined ? value : value.replaceAll(spoken, "\u0000captions");
|
|
146
|
+
return carded === undefined ? unsaid : unsaid.replaceAll(script, "\u0000cards");
|
|
147
|
+
}), output, [
|
|
148
|
+
...(carded === undefined || font === undefined
|
|
149
|
+
? []
|
|
150
|
+
: [carded, fileIdentity(font.path)]),
|
|
151
|
+
...(drawn === undefined || said === undefined ? [] : [said, ...drawn.identity()]),
|
|
152
|
+
], drawn?.stand());
|
|
117
153
|
keys.add(key);
|
|
118
154
|
if (reuseClip(cache, key, output)) {
|
|
119
155
|
rendered += weight;
|
|
@@ -128,17 +164,17 @@ async function renderWith(run, encode) {
|
|
|
128
164
|
}
|
|
129
165
|
await runFfmpeg({
|
|
130
166
|
bin: encoder,
|
|
131
|
-
...(cards.length > 0 ? { cwd: workspace } : {}),
|
|
167
|
+
...(cards.length > 0 || drawn !== undefined ? { cwd: workspace } : {}),
|
|
132
168
|
args,
|
|
133
169
|
signal,
|
|
134
170
|
log: run.log,
|
|
135
171
|
priority,
|
|
136
172
|
onProgress: (elapsedMs) => {
|
|
137
|
-
running.set(
|
|
173
|
+
running.set(made.name, Math.min(elapsedMs * clipWeight, weight));
|
|
138
174
|
tell();
|
|
139
175
|
},
|
|
140
176
|
});
|
|
141
|
-
running.delete(
|
|
177
|
+
running.delete(made.name);
|
|
142
178
|
rendered += weight;
|
|
143
179
|
if (cache !== undefined && key !== undefined) {
|
|
144
180
|
try {
|
|
@@ -191,7 +227,7 @@ async function renderWith(run, encode) {
|
|
|
191
227
|
throw failed.error;
|
|
192
228
|
if (played === undefined)
|
|
193
229
|
throw new Error("the render was canceled");
|
|
194
|
-
const burnsHere =
|
|
230
|
+
const burnsHere = twice && parts.length <= 1;
|
|
195
231
|
await runFfmpeg({
|
|
196
232
|
bin: burnsHere ? encoder : run.bin,
|
|
197
233
|
cwd: run.cwd,
|
|
@@ -218,6 +254,55 @@ async function renderWith(run, encode) {
|
|
|
218
254
|
rmSync(workspace, { recursive: true, force: true });
|
|
219
255
|
}
|
|
220
256
|
}
|
|
257
|
+
// The whole video's captions, read so each clip can draw its own part of them.
|
|
258
|
+
function ownCaptions(run, fps) {
|
|
259
|
+
const again = "Press Make the video again in the project's Video section";
|
|
260
|
+
const folder = run.cwd;
|
|
261
|
+
if (folder === undefined)
|
|
262
|
+
throw new Error(internalError("the captions have no folder", again));
|
|
263
|
+
let script;
|
|
264
|
+
try {
|
|
265
|
+
script = readFileSync(join(folder, "subtitles.ass"), "utf8");
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
throw new Error(internalError(`the captions could not be read: ${errorText(error)}`, again), {
|
|
269
|
+
cause: error,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return { captions: readCaptions(script, fps), folder };
|
|
273
|
+
}
|
|
274
|
+
// What the clips draw their own captions with, put beside them: the caption fonts, and the
|
|
275
|
+
// speaker portraits where the caption folder holds them. That folder is written anew for
|
|
276
|
+
// every render, so `identity` and `stand` name the files in a clip's cache key by what they
|
|
277
|
+
// hold rather than by their path and date.
|
|
278
|
+
function captionFiles(own, portraits = [], workspace) {
|
|
279
|
+
const from = join(own.folder, "fonts");
|
|
280
|
+
const to = join(workspace, captionFonts);
|
|
281
|
+
if (existsSync(from))
|
|
282
|
+
cpSync(from, to, { recursive: true });
|
|
283
|
+
else
|
|
284
|
+
mkdirSync(to, { mode: 0o700 });
|
|
285
|
+
const placed = portraits.map((portrait) => ({
|
|
286
|
+
...portrait,
|
|
287
|
+
path: resolve(own.folder, portrait.path),
|
|
288
|
+
}));
|
|
289
|
+
let identity;
|
|
290
|
+
let stand;
|
|
291
|
+
return {
|
|
292
|
+
fonts: captionFonts,
|
|
293
|
+
portraits: placed,
|
|
294
|
+
identity: () => {
|
|
295
|
+
identity ??= readdirSync(to)
|
|
296
|
+
.toSorted()
|
|
297
|
+
.map((name) => `${name}|${contentIdentity(join(to, name))}`);
|
|
298
|
+
return identity;
|
|
299
|
+
},
|
|
300
|
+
stand: () => {
|
|
301
|
+
stand ??= new Map(placed.map((portrait) => [portrait.path, `portrait:${contentIdentity(portrait.path)}`]));
|
|
302
|
+
return stand;
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
221
306
|
// The video's finished sound as AAC in the working folder: the narration, silences and bed
|
|
222
307
|
// mixed, and with Level the volume mastered first, alone and then as one file.
|
|
223
308
|
async function renderSound(run, edit, workspace, signal) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { closeSync, openSync, readSync } from "node:fs";
|
|
2
|
+
import { errorText } from "../../kernel/errors.js";
|
|
3
|
+
import { pictureSize } from "../designs/picture-size.js";
|
|
4
|
+
// A PNG states its size in its first 24 bytes; a JPEG after its metadata, which a camera's
|
|
5
|
+
// thumbnail and colour profile can make a few hundred kilobytes.
|
|
6
|
+
const headBytes = 512 * 1024;
|
|
7
|
+
// Each still's own size, from the start of its file: a still with no more pixels than the
|
|
8
|
+
// frame is sampled from a smaller base (`move.ts`). One whose size cannot be read is left
|
|
9
|
+
// out and treated as a large one, which loses nothing and only costs time.
|
|
10
|
+
export function stillSizes(shots, log) {
|
|
11
|
+
const sizes = new Map();
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const head = Buffer.alloc(headBytes);
|
|
14
|
+
for (const { source } of shots) {
|
|
15
|
+
if (source.kind !== "image" || seen.has(source.path))
|
|
16
|
+
continue;
|
|
17
|
+
seen.add(source.path);
|
|
18
|
+
try {
|
|
19
|
+
const file = openSync(source.path, "r");
|
|
20
|
+
try {
|
|
21
|
+
const size = pictureSize(head.subarray(0, readSync(file, head, 0, head.length, 0)));
|
|
22
|
+
if (size !== undefined)
|
|
23
|
+
sizes.set(source.path, size);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
closeSync(file);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// The render refuses a still it cannot open, in ffmpeg's own words; this only notes it.
|
|
31
|
+
log.write("warn", "video.still", {
|
|
32
|
+
detail: `could not read the size of ${source.path}: ${errorText(error)}`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return sizes;
|
|
37
|
+
}
|
|
@@ -116,10 +116,10 @@ The volume fields show only while the switch is on. A project keeps what it star
|
|
|
116
116
|
| Control | What it does | Default |
|
|
117
117
|
|---|---|---|
|
|
118
118
|
| **Video encoder** | What turns the frames into the finished file. **Processor (x264)** is the one every computer has. **NVIDIA graphics card (NVENC)** encodes on the card at its highest-quality settings (preset p7, tune hq, constant quality) and leaves the processor for the rest. It is offered only when Slopify finds an ffmpeg with NVENC (its own, else the `ffmpeg` on your `PATH` or `/usr/bin/ffmpeg`) that passes a tiny test encode; otherwise the line under it says "No working NVIDIA graphics card was found on this computer" (or that none was found) and that videos are encoded on the processor, with what the test printed under **Details**. | Processor (x264) |
|
|
119
|
-
| **Clip encoding** | How hard the processor works on
|
|
119
|
+
| **Clip encoding** | How hard the processor works on a video with captions drawn into the picture. **Thorough** is x264's medium preset. **Fast** takes about a sixth less time for a slightly softer picture. Where each image is shown once, every clip draws its own captions and is encoded once, and Fast is x264's faster preset. Where the same images come round again, their clips are encoded once and the captions are drawn over the joined video in a second encode, and Fast is the veryfast preset for those clips (CRF 16). Has no effect without captions in the video, or with the NVIDIA encoder. | Thorough |
|
|
120
120
|
| **Encoding priority** | **Background (your other programs come first)** runs every ffmpeg of a video, short or audio file, its volume mastering included, below normal priority, and that of the style preview, template samples, designs and posts' pictures too (nice 10 on Linux and macOS, below-normal on Windows): your browser, games and other programs take the processor first and the video gets what is left. **Normal** competes with them as an equal. The finished video is the same either way. | Background |
|
|
121
121
|
|
|
122
|
-
What they cost and give, measured on
|
|
122
|
+
What they cost and give, measured on the first 24 images (11.5 minutes) of a real project with captions in the video, each image shown once (16-core processor, RTX 5080): **Thorough** took 83 seconds; **Fast** took 69, a sixth less, for a slightly softer picture (1.2 VMAF less) and a file a sixth smaller. **NVIDIA** took 42 seconds, half the waiting (the zoom and pan on each image still runs on the processor), but with a visibly softer picture than x264 (about 2.5 VMAF less at the same file size, measured in 4.0): pick it when the time matters more than the last bit of sharpness. In a video whose images come round again, Fast cut the waiting by a fifth as well (118 seconds against 145) for 0.7 VMAF less. **Background** makes no difference to the file at all.
|
|
123
123
|
|
|
124
124
|
If the NVIDIA encoder is chosen but stops working (a driver update, the card busy elsewhere), the video is encoded on the processor instead, never failed, and the project's Video part says so, with the reason and where to change it. Slopify checks for the card once per start; restart Slopify after installing a driver or an ffmpeg with NVENC.
|
|
125
125
|
|