@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.
Files changed (36) hide show
  1. package/dist/edge/http/projects.js +4 -1
  2. package/dist/edge/http/settings.js +2 -0
  3. package/dist/extension/slopify-studio-chrome.zip +0 -0
  4. package/dist/extension/slopify-studio-firefox.zip +0 -0
  5. package/dist/main.js +8 -1
  6. package/dist/patch-notes/4.3.5.md +30 -0
  7. package/dist/patch-notes/4.4.0.md +37 -0
  8. package/dist/patch-notes/index.json +12 -0
  9. package/dist/slices/rebuild/runtime-export-short.js +4 -2
  10. package/dist/slices/rebuild/runtime-export.js +5 -2
  11. package/dist/slices/rebuild/runtime-provider.js +14 -0
  12. package/dist/slices/revisions/view.js +19 -8
  13. package/dist/slices/settings/model.js +1 -0
  14. package/dist/slices/settings/playback.js +11 -1
  15. package/dist/slices/shorts/captions.js +2 -1
  16. package/dist/slices/storage/named-ids.js +46 -0
  17. package/dist/slices/storage/trim.js +24 -12
  18. package/dist/slices/studio/videos.js +20 -6
  19. package/dist/slices/subtitles/captions.js +2 -1
  20. package/dist/slices/video/cards.js +2 -0
  21. package/dist/slices/video/clip-cache.js +15 -7
  22. package/dist/slices/video/clip-captions.js +120 -0
  23. package/dist/slices/video/colour.js +22 -0
  24. package/dist/slices/video/encoding.js +23 -5
  25. package/dist/slices/video/ffmpeg.js +60 -71
  26. package/dist/slices/video/look.js +23 -9
  27. package/dist/slices/video/move.js +89 -0
  28. package/dist/slices/video/plan.js +58 -11
  29. package/dist/slices/video/pool.js +6 -5
  30. package/dist/slices/video/render-gate.js +45 -0
  31. package/dist/slices/video/slideshow.js +105 -20
  32. package/dist/slices/video/still-sizes.js +37 -0
  33. package/dist/tutorials/Settings-Reference.md +2 -2
  34. package/dist/web/assets/{index-BwKV_9F3.js → index-CA_I2trg.js} +160 -160
  35. package/dist/web/index.html +1 -1
  36. package/package.json +1 -1
@@ -122,7 +122,10 @@ export function projectRoutes(deps) {
122
122
  : "This project no longer exists. Go back to Projects to pick another.",
123
123
  });
124
124
  }
125
- if (deps.catalogue !== undefined)
125
+ // Only a project with no saved version yet needs one adopted: asked of one that has,
126
+ // adopting builds that whole version and drops it, on the request every live event
127
+ // and every return to the page repeats.
128
+ if (deps.catalogue !== undefined && currentRevisionId(deps.db, project.id) === undefined)
126
129
  adoptBaseline(deps, project.id);
127
130
  const holds = projectHolds(deps.db, { projectId: project.id });
128
131
  const stopped = holds.stopped.has(project.id);
@@ -50,6 +50,7 @@ const playbackBody = z.object({
50
50
  videoEncoder: z.enum(videoEncoders).optional(),
51
51
  clipEncodeSpeed: z.enum(clipEncodeSpeeds).optional(),
52
52
  renderPriority: z.enum(renderPriorities).optional(),
53
+ videoRenderConcurrency: z.number().optional(),
53
54
  });
54
55
  // The return type is inferred so Hono keeps the route types the SPA's client is
55
56
  // generated from; see stagingRoutes.
@@ -69,6 +70,7 @@ export function settingsRoutes(deps) {
69
70
  videoEncoder: body.videoEncoder ?? saved.videoEncoder,
70
71
  clipEncodeSpeed: body.clipEncodeSpeed ?? saved.clipEncodeSpeed,
71
72
  renderPriority: body.renderPriority ?? saved.renderPriority,
73
+ videoRenderConcurrency: body.videoRenderConcurrency ?? saved.videoRenderConcurrency,
72
74
  });
73
75
  if (!result.ok) {
74
76
  return problem(c, {
package/dist/main.js CHANGED
@@ -121,6 +121,7 @@ import { createPriceCache } from "./slices/template-studio/service.js";
121
121
  import { createTrashPurge } from "./slices/trash/service.js";
122
122
  import { createNvencProbe, noNvenc, renderMachine, } from "./slices/video/encoding.js";
123
123
  import { probeDurationMs, runFfmpegAt } from "./slices/video/ffmpeg.js";
124
+ import { createRenderGate } from "./slices/video/render-gate.js";
124
125
  import { watchActivation } from "./updater/candidate.js";
125
126
  import { launchUpdate } from "./updater/install.js";
126
127
  import { isUpdateToken } from "./updater/model.js";
@@ -1072,7 +1073,10 @@ export async function boot(config, options = {}) {
1072
1073
  }
1073
1074
  export function wireRunner({ onFinished, audioPreviews, db, paths, clock, ids, log, hub, telemetry, flusher, registry, catalogue, ffmpeg, nvenc = async () => ({ available: false, reason: noNvenc }),
1074
1075
  // Settings → Production defaults → Subtitle timing model, read as each alignment starts.
1075
- alignSubtitles: aligner = alignSubtitlesWith(() => readSettings({ db, log }).subtitleModel), }) {
1076
+ alignSubtitles: aligner = alignSubtitlesWith(() => readSettings({ db, log }).subtitleModel),
1077
+ // Settings → Production defaults → Videos rendered at once, read as each render asks for its
1078
+ // place, so a change takes hold without a restart.
1079
+ renderGate = createRenderGate(() => readSettings({ db, log }).videoRenderConcurrency), }) {
1076
1080
  // A stage counts what it did and the queue is flushed after each new event. `record`
1077
1081
  // swallows its own failures, so this can neither fail a stage nor widen what leaves the
1078
1082
  // machine - the payload allow-list is checked inside it.
@@ -1090,6 +1094,9 @@ alignSubtitles: aligner = alignSubtitlesWith(() => readSettings({ db, log }).sub
1090
1094
  alignSubtitles: aligner,
1091
1095
  // Settings → Production defaults → Rendering, read as each render starts.
1092
1096
  renderMachine: (projectId) => renderMachine({ settings: readSettings({ db, log }), nvenc, log, projectId }),
1097
+ // One queue for every render this computer makes, so a second video waits rather than
1098
+ // taking the processor and memory the first one and the page are using.
1099
+ renderGate,
1093
1100
  audioPreviews,
1094
1101
  count,
1095
1102
  };
@@ -0,0 +1,30 @@
1
+ # Slopify 4.3.5
2
+
3
+ Released 12 November 2026.
4
+
5
+ The picture is now timed to the narration, a run no longer takes the whole computer, and a video's shorts stay in Ready to upload until every one of them is up.
6
+
7
+ ## Each image holds for its share of the narration
8
+
9
+ - **A shot's length is now worked out from the narration it covers** — the time left after the figure cards, divided by the number of images — rather than from a fixed number of seconds. The images a video was made with span the whole video, in order, each one once.
10
+ - **A sparse set still keeps cutting.** Where dividing the narration that way would leave one image on screen for more than two minutes, the shot falls back to the length set for the project, so the picture keeps moving rather than settling on a still.
11
+ - **Measured on a real episode:** 240 images now plan 244 shots across the whole timeline.
12
+
13
+ ## This computer renders one video at a time
14
+
15
+ - **Settings → Production defaults → Videos rendered at once,** one to four, one by default. A render decodes a whole picture track and encodes hours of it, so a second one does not take half the time each: they share the processor, the disk and the memory, and enough of them together leave the app with too little of each to answer the page.
16
+ - **A render that has to wait is not refused,** it takes its turn and finishes later. Shorts queue beside long videos, since a short is a render like any other.
17
+ - **The audio export does not queue.** It is neither long enough nor heavy enough to be worth holding a place for, so turning narration into a WAV never waits behind a video.
18
+ - **The number is read as each render asks for its place,** so raising it lets a waiting render start without a restart, and lowering it takes hold as the renders running now finish.
19
+
20
+ ## A video's shorts stay in Ready to upload until they are up
21
+
22
+ - **The project's uploaded mark now stands for every upload it has,** the long video and each short, not for the long video alone. It was one fact before — the long video on YouTube meant the project was uploaded — and that quietly took the shorts still waiting out of Ready to upload with it.
23
+ - **Why it bit:** Studio re-reads the long video after each upload. Uploading short 1 made Slopify record the long video again, which re-applied the mark, which hid shorts 2 and 3. The extension then said "Nothing waits to be uploaded" while two shorts had never gone up, and taking the mark off by hand lasted only until the next upload re-applied it.
24
+ - **Nothing changed about what the extension already knew:** every item in its list carried its own uploaded flag all along. Only the project-level mark was wrong, so Projects, Home, the calendar and the extension now agree without any of them being taught about shorts.
25
+ - **Forgetting an upload that was on YouTube takes the mark off again,** a short's as well as the long video's, since the mark stands for all of them. An upload only filled in Studio never set the mark, so forgetting it still leaves a mark made by hand.
26
+
27
+ ## New images appear as they are made
28
+
29
+ - **The open page now hears about each image as it lands,** so the pictures fill in while a run works instead of only when you reload. The progress beside them already moved live; the pictures themselves did not.
30
+ - **A long run does not flood the page.** A run of 240 images collapses into a few refreshes rather than one for every image.
@@ -0,0 +1,37 @@
1
+ # Slopify 4.4.0
2
+
3
+ Released 13 November 2026.
4
+
5
+ Pans and zooms now move evenly, a video with captions in the picture is made in a little over half the time, videos keep the colours of their pictures, and opening a finished project no longer stalls the app.
6
+
7
+ ## Pans and zooms no longer shake
8
+
9
+ - **A slow pan now moves by the same amount every frame.** Since images are held for their share of the narration, a shot runs about half a minute and a pan advances under half a pixel a frame. The picture could only be placed on whole pixels, so it stood still for a frame and then jumped: measured on a finished video, steps between nothing and 0.73 of a pixel where 0.46 was meant. They now measure 0.39 to 0.50, and what is left is the encoder's own noise.
10
+ - **A zoom holds its centre.** It wandered by up to 0.4 of a pixel from one frame to the next; it now moves by under 0.05.
11
+ - **The picture is placed between pixels,** in one pass at the frame's own size, instead of being enlarged four times and stepped. Fine detail is as sharp as before, within three percent either way.
12
+ - **Files are about three percent larger at the same quality setting,** because a picture that really moves every frame gives the encoder more to describe than one that stands still every other frame.
13
+ - **A still larger than the frame keeps its detail,** as before: it is sampled from a larger copy than a still with no more pixels than the frame, and each is kept away from the one size where fine detail would flicker.
14
+
15
+ ## A video with captions is encoded once
16
+
17
+ - **Where each image is shown once, every clip now draws its own captions.** Until now the clips were encoded, joined, and the whole video encoded a second time to draw the captions over it, so every frame was compressed twice, the second time from a copy the first had already softened. Each frame is now sampled from its still, captioned and encoded in one go, and the join only copies.
18
+ - **It takes a little over half the time.** Measured on the first 24 images (11.5 minutes) of a real project on a 16-core processor: 83 seconds, against 155 in 4.3.5. The picture scores slightly higher against a lossless render (93.8 VMAF against 93.2 for two encodes), since it is compressed once, and the file is 1% larger.
19
+ - **A video whose same clips come round again keeps the two encodes,** because there they are the cheaper way: twelve stills that revolve for two hours at a fixed number of seconds each are a few minutes of distinct clips, and decoding a clip costs less than sampling its still again. Slopify picks per video: clips draw their own captions when the distinct clips are a third of the video or more, which a video whose shots follow the narration always is, since no two shots are the same length.
20
+ - **Changing one image or one caption no longer re-encodes the video.** Clips that draw their own captions are kept with them for the next render, so only the clips that changed are made again; before, any change sent the whole video through the caption encode. A two-hour video with 240 images took 14.7 minutes to make, sound included, and 1.7 minutes to make again with nothing changed.
21
+ - **Captions land on the exact frame.** A caption that starts at the very moment a frame is shown is now on that frame; a rounding used to put a few captions in a hundred one frame late. Checked frame by frame on that 11.5-minute render: 5 frames of 20,655 differ, each by that one frame.
22
+ - **Clip encoding: Fast now means the same for every video with captions,** about a sixth less time for a slightly softer picture. For clips that draw their own captions it is x264's faster preset (69 seconds against 83, 1.2 VMAF less, a sixth smaller); the two-encode route keeps what Fast always did there.
23
+
24
+ ## Videos keep the colours of their pictures
25
+
26
+ - **Every video is now BT.709 and says so.** Pictures were turned into video with the older BT.601 formula and the file carried no colour labels, while players and YouTube read an unlabelled HD video as BT.709. The result was a slight warm cast on every video: reds a few steps too strong, blues a few too weak.
27
+ - **This covers every still that goes into a video:** plain, zooming and panning pictures, the four colour grades, portraits beside captions and the atmosphere layers. A clip that is already video keeps its own colours and only gets the label.
28
+ - **Coloured captions and chapter cards match as well,** with the NVIDIA encoder too. White text never changed.
29
+ - **Videos already made stay as they are;** make one again to get the corrected colours. The first render after updating encodes every clip afresh rather than reusing saved ones, since their colours differ.
30
+
31
+ ## Opening a finished project no longer stalls the app
32
+
33
+ - **A finished project's page opens without freezing everything else.** Working out what Keep outputs only would free read every saved version once for each of the project's files: about two and a half seconds on a two-hour video with 600 files, during which no page got an answer, and it ran again on every visit and every return to the window. It now reads them once, in about two hundredths of a second, and answers the same.
34
+ - **Settings → Storage answers in a couple of seconds,** where it took over twenty with 170 projects. It asked the same question of every project in turn.
35
+ - **A running step no longer keeps the page asking for the whole project.** Each progress report, up to two a second, made the open page fetch everything it shows again, the saved version included (megabytes on a finished project). A report now fetches the meter and the cost, once a second at most, and the rest only every few seconds.
36
+ - **Coming back to the window no longer fetches the saved version and the name checks again.** Live events and saves already keep those fresh. Everything else is still asked again on return, which is how the page learns what the extension did in YouTube Studio.
37
+ - **Reading a saved version takes about half the time,** for every page of a project and every step of a run: its files are looked up once, not one at a time.
@@ -1,4 +1,16 @@
1
1
  [
2
+ {
3
+ "id": "4.4.0",
4
+ "title": "Slopify 4.4.0",
5
+ "version": "4.4.0",
6
+ "date": "2026-11-13"
7
+ },
8
+ {
9
+ "id": "4.3.5",
10
+ "title": "Slopify 4.3.5",
11
+ "version": "4.3.5",
12
+ "date": "2026-11-12"
13
+ },
2
14
  {
3
15
  "id": "4.3.4",
4
16
  "title": "Slopify 4.3.4",
@@ -5,6 +5,7 @@ import { renderShort, shortFrame } from "../shorts/render.js";
5
5
  import { allocateAsset, discardPreparedAssets, sealAsset } from "../storage/assets.js";
6
6
  import { projectDir } from "../storage/layout.js";
7
7
  import { probeDurationMs } from "../video/ffmpeg.js";
8
+ import { openRenderGate } from "../video/render-gate.js";
8
9
  import { exportMachine, slideshowImages, warningsOf, } from "./runtime-export.js";
9
10
  import { preparedResult, preparedText, publishResult } from "./runtime-publication.js";
10
11
  import { readTimingWords } from "./runtime-subtitles.js";
@@ -29,7 +30,8 @@ export async function executeShortExport(deps, context, piece, snapshot, timelin
29
30
  const relativePath = (path) => relative(directory, path).split(sep).join("/");
30
31
  try {
31
32
  const machine = await exportMachine(deps, context.work.projectId);
32
- const master = await renderShort({
33
+ // A short is a render like any other, so it waits in the same queue as the long video.
34
+ const master = await (deps.renderGate ?? openRenderGate).hold(() => renderShort({
33
35
  bin: deps.ffmpeg,
34
36
  machine: machine.machine,
35
37
  notice: machine.notice,
@@ -55,7 +57,7 @@ export async function executeShortExport(deps, context, piece, snapshot, timelin
55
57
  current: Math.min(100, Math.round(elapsedMs / (seconds * 10))),
56
58
  total: 100,
57
59
  }),
58
- });
60
+ }));
59
61
  context.signal.throwIfAborted();
60
62
  const durationMs = await probeDurationMs(deps.ffmpeg, pending.absolutePath, context.signal, deps.log);
61
63
  const asset = sealAsset(deps, pending);
@@ -12,6 +12,7 @@ import { audioExportArgs } from "../video/audio-export.js";
12
12
  import { withPaths } from "../video/edit-list.js";
13
13
  import { runFfmpeg } from "../video/ffmpeg.js";
14
14
  import { planRender } from "../video/plan.js";
15
+ import { openRenderGate } from "../video/render-gate.js";
15
16
  import { renderSlideshow } from "../video/slideshow.js";
16
17
  import { writePortraits } from "../voices/portraits.js";
17
18
  import { linesLevelled } from "./recipe-lines.js";
@@ -197,8 +198,10 @@ export async function executeExportRecipe(deps, context, piece) {
197
198
  }
198
199
  }
199
200
  }
201
+ // The picture render waits its turn. The audio export above does not: it is neither long
202
+ // enough nor heavy enough to be worth holding a place for.
200
203
  else
201
- master = await renderSlideshow({
204
+ master = await (deps.renderGate ?? openRenderGate).hold(() => renderSlideshow({
202
205
  bin: deps.ffmpeg,
203
206
  edit: plan.editList,
204
207
  output: plan.output,
@@ -213,7 +216,7 @@ export async function executeExportRecipe(deps, context, piece) {
213
216
  ...(goal === undefined ? {} : { master: goal }),
214
217
  machine: machine.machine,
215
218
  notice: machine.notice,
216
- });
219
+ }));
217
220
  context.signal.throwIfAborted();
218
221
  const asset = sealAsset(deps, pending);
219
222
  prepared.push(preparedResult(deps, context, piece, wav ? "audio_export" : "video", asset, Math.round(totalSeconds * 1000), {
@@ -161,6 +161,20 @@ export async function executeProviderRecipe(deps, context, providers, piece) {
161
161
  ...(variant === undefined || variant === 1 ? {} : { index: variant }),
162
162
  });
163
163
  await publishResult(deps, context, piece, [output], { prompt }, asset);
164
+ // The frame names the output and its place, not the row or the file behind them, so the
165
+ // open page refetches on it rather than painting from it (`web/src/events.ts`); a run of
166
+ // 240 images coalesces those refetches there, so every image still sends its own frame.
167
+ context.emit({
168
+ type: "image.landed",
169
+ projectId: context.work.projectId,
170
+ outputId: output.output.id,
171
+ // Thumbnails and the establishing image have no place in the image order; the page
172
+ // refetches on any of them just the same.
173
+ index: index ?? 0,
174
+ revisionId: context.work.revisionId,
175
+ workId: context.work.workId,
176
+ workPieceId: piece.id,
177
+ });
164
178
  if (softened !== undefined)
165
179
  clearSoftening(deps.db, context.work.projectId, [piece.key]);
166
180
  deps.count?.("stage.completed", {
@@ -1,5 +1,4 @@
1
1
  import { readFileSync, statSync } from "node:fs";
2
- import { z } from "zod";
3
2
  import { outputPath } from "../storage/layout.js";
4
3
  import { narrationJoinPiecesOfProject, narrationJoinsOfProject } from "./manifest-repo.js";
5
4
  import { currentRevisionId, outputsForRevision, piecesForRevision, revisionById } from "./repo.js";
@@ -7,15 +6,27 @@ export function getRevisionView(deps, projectId, revisionId) {
7
6
  const revision = revisionById(deps.db, projectId, revisionId);
8
7
  if (revision === undefined)
9
8
  return undefined;
9
+ // The project's files are read once and each looked for on disk once: a finished project's
10
+ // version names over a thousand, and asking for them one at a time was most of this view,
11
+ // which every page of the project and every step of a run builds.
12
+ const paths = new Map();
13
+ for (const row of deps.db
14
+ .prepare("SELECT id,path FROM project_assets WHERE project_id=?")
15
+ .all(projectId))
16
+ if (typeof row.id === "string" && typeof row.path === "string")
17
+ paths.set(row.id, row.path);
18
+ const onDisk = new Map();
10
19
  const available = (assetId) => {
11
- const row = deps.db
12
- .prepare("SELECT path FROM project_assets WHERE project_id=? AND id=?")
13
- .get(projectId, assetId);
14
- if (row === undefined)
20
+ const known = onDisk.get(assetId);
21
+ if (known !== undefined)
22
+ return known;
23
+ const path = paths.get(assetId);
24
+ if (path === undefined)
15
25
  throw new Error(`Revision asset ${assetId} is not registered.`);
16
- const path = z.object({ path: z.string() }).parse(row).path;
17
- return (statSync(outputPath(deps.paths, projectId, path), { throwIfNoEntry: false })?.isFile() ===
18
- true);
26
+ const found = statSync(outputPath(deps.paths, projectId, path), { throwIfNoEntry: false })?.isFile() ===
27
+ true;
28
+ onDisk.set(assetId, found);
29
+ return found;
19
30
  };
20
31
  const outputs = outputsForRevision(deps.db, projectId, revisionId).map((row) => ({
21
32
  ...row,
@@ -149,4 +149,5 @@ export const defaultSettings = {
149
149
  videoEncoder: "cpu",
150
150
  clipEncodeSpeed: "thorough",
151
151
  renderPriority: "background",
152
+ videoRenderConcurrency: 1,
152
153
  };
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { englishSubtitleModels } from "../../kernel/ports/subtitles.js";
3
3
  import { silenceGapSecondsMax } from "../admission/rules.js";
4
4
  import { loudnessFields } from "../loudness/model.js";
5
- import { clipEncodeSpeeds, renderPriorities, videoEncoders } from "../video/encoding.js";
5
+ import { clipEncodeSpeeds, renderPriorities, videoEncoders, videoRenderConcurrencyMax, } from "../video/encoding.js";
6
6
  import { appearances, defaultSettings } from "./model.js";
7
7
  import { readJsonSetting, writeSetting } from "./repo.js";
8
8
  // The `settings` table is key/value, so each setting is its own row and a value the app
@@ -14,12 +14,14 @@ const subtitleModelKey = "subtitleModel";
14
14
  const videoEncoderKey = "videoEncoder";
15
15
  const clipEncodeSpeedKey = "clipEncodeSpeed";
16
16
  const renderPriorityKey = "renderPriority";
17
+ const videoRenderConcurrencyKey = "videoRenderConcurrency";
17
18
  const silenceGapValue = z.number().int().min(0).max(silenceGapSecondsMax);
18
19
  const appearanceValue = z.enum(appearances);
19
20
  const subtitleModelValue = z.enum(englishSubtitleModels);
20
21
  const videoEncoderValue = z.enum(videoEncoders);
21
22
  const clipEncodeSpeedValue = z.enum(clipEncodeSpeeds);
22
23
  const renderPriorityValue = z.enum(renderPriorities);
24
+ const videoRenderConcurrencyValue = z.number().int().min(1).max(videoRenderConcurrencyMax);
23
25
  const loudnessValue = z.object({
24
26
  enabled: z.boolean(),
25
27
  videoLufs: z.number(),
@@ -34,6 +36,7 @@ export function readSettings(deps) {
34
36
  videoEncoder: parsed(deps, videoEncoderKey, videoEncoderValue, defaultSettings.videoEncoder),
35
37
  clipEncodeSpeed: parsed(deps, clipEncodeSpeedKey, clipEncodeSpeedValue, defaultSettings.clipEncodeSpeed),
36
38
  renderPriority: parsed(deps, renderPriorityKey, renderPriorityValue, defaultSettings.renderPriority),
39
+ videoRenderConcurrency: parsed(deps, videoRenderConcurrencyKey, videoRenderConcurrencyValue, defaultSettings.videoRenderConcurrency),
37
40
  };
38
41
  }
39
42
  export function saveSettings(deps, settings) {
@@ -77,6 +80,12 @@ export function saveSettings(deps, settings) {
77
80
  message: "Choose Normal or Background in Settings → Production defaults → Encoding priority.",
78
81
  });
79
82
  }
83
+ if (!videoRenderConcurrencyValue.safeParse(settings.videoRenderConcurrency).success) {
84
+ fields.push({
85
+ field: "videoRenderConcurrency",
86
+ message: `Enter a whole number between 1 and ${String(videoRenderConcurrencyMax)} in Settings → Production defaults → Videos rendered at once.`,
87
+ });
88
+ }
80
89
  if (fields.length > 0) {
81
90
  return { ok: false, fields };
82
91
  }
@@ -87,6 +96,7 @@ export function saveSettings(deps, settings) {
87
96
  writeSetting(deps.db, videoEncoderKey, JSON.stringify(settings.videoEncoder));
88
97
  writeSetting(deps.db, clipEncodeSpeedKey, JSON.stringify(settings.clipEncodeSpeed));
89
98
  writeSetting(deps.db, renderPriorityKey, JSON.stringify(settings.renderPriority));
99
+ writeSetting(deps.db, videoRenderConcurrencyKey, JSON.stringify(settings.videoRenderConcurrency));
90
100
  return { ok: true, settings };
91
101
  }
92
102
  // A stored value is JSON, and a hand-edited database is the only way it can be anything
@@ -158,7 +158,8 @@ export function shortCaptionsAss(words, style) {
158
158
  const title = style.title === undefined || style.title.text.trim() === ""
159
159
  ? undefined
160
160
  : { ...titleLayout(style.title.text, style), seconds: style.title.seconds };
161
- const header = `[Script Info]\nScriptType: v4.00+\nPlayResX: ${String(style.width)}\nPlayResY: ${String(style.height)}\nWrapStyle: 2\nScaledBorderAndShadow: yes\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\nStyle: Short,${name},${String(size)},${white},${white},&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,7,3,5,${String(sideMargin)},${String(sideMargin)},0,1\n${title === undefined ? "" : `Style: Title,${name},${String(title.size)},${white},${white},&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,6,3,8,${String(sideMargin)},${String(sideMargin)},0,1\n`}\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`;
161
+ // YCbCr Matrix: without it, ffmpeg 7.1 and later draw the colours as BT.601 on a BT.709 picture.
162
+ const header = `[Script Info]\nScriptType: v4.00+\nPlayResX: ${String(style.width)}\nPlayResY: ${String(style.height)}\nYCbCr Matrix: TV.709\nWrapStyle: 2\nScaledBorderAndShadow: yes\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\nStyle: Short,${name},${String(size)},${white},${white},&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,7,3,5,${String(sideMargin)},${String(sideMargin)},0,1\n${title === undefined ? "" : `Style: Title,${name},${String(title.size)},${white},${white},&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,6,3,8,${String(sideMargin)},${String(sideMargin)},0,1\n`}\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`;
162
163
  const groups = captionGroups(words);
163
164
  // The headline sits on a layer of its own, so a caption never hides it.
164
165
  const events = title === undefined
@@ -0,0 +1,46 @@
1
+ // Which of `ids` occur anywhere in `texts`, exactly as SQL's instr() would find them, without
2
+ // reading every text once per id: asked that way, a finished project's 600 file ids against 4 MB
3
+ // of saved revisions took over a second, on the one thread that answers every page.
4
+ //
5
+ // Ids of one length that begin with the same character are looked for together: every place
6
+ // their shared beginning occurs is read once and looked up. A project's ids are made close
7
+ // together and share most of their beginning, so those places are the ids themselves.
8
+ export function idsNamedIn(ids, texts) {
9
+ const found = new Set();
10
+ const groups = new Map();
11
+ for (const id of new Set(ids)) {
12
+ if (id === "") {
13
+ if (texts.length > 0)
14
+ found.add(id);
15
+ continue;
16
+ }
17
+ const key = `${String(id.length)}:${id.charAt(0)}`;
18
+ const group = groups.get(key);
19
+ if (group === undefined)
20
+ groups.set(key, [id]);
21
+ else
22
+ group.push(id);
23
+ }
24
+ for (const group of groups.values()) {
25
+ const start = sharedStart(group);
26
+ const length = group[0]?.length ?? 0;
27
+ const wanted = new Set(group);
28
+ for (const text of texts)
29
+ for (let at = text.indexOf(start); at !== -1; at = text.indexOf(start, at + 1)) {
30
+ const candidate = text.slice(at, at + length);
31
+ if (wanted.has(candidate))
32
+ found.add(candidate);
33
+ }
34
+ }
35
+ return found;
36
+ }
37
+ function sharedStart(ids) {
38
+ let shared = ids[0] ?? "";
39
+ for (const id of ids) {
40
+ let same = 0;
41
+ while (same < shared.length && shared.charAt(same) === id.charAt(same))
42
+ same += 1;
43
+ shared = shared.slice(0, same);
44
+ }
45
+ return shared;
46
+ }
@@ -6,6 +6,7 @@ import { bundledSampleProjects } from "../onboarding/state.js";
6
6
  import { notTemplateSample } from "../template-studio/repo.js";
7
7
  import { projectSettled } from "./arrange.js";
8
8
  import { backupsFolderName, outputPath, projectDir } from "./layout.js";
9
+ import { idsNamedIn } from "./named-ids.js";
9
10
  import { pieceFile } from "./reconcile.js";
10
11
  // Keep outputs only: a finished project drops the working files it was made from (narration
11
12
  // parts, subtitle timing, render settings) and keeps what gets published, the images the
@@ -42,14 +43,16 @@ export function projectStorage(deps, projectId) {
42
43
  const files = filesOf(deps.paths, projectId);
43
44
  const outputs = outputPaths(deps.db, projectId);
44
45
  const sample = bundledSampleProjects(deps.db).has(projectId);
46
+ // Read once: what may be removed and what History may drop both turn on it.
47
+ const supplied = sample ? new Set() : suppliedPaths(deps.db, projectId);
45
48
  const removable = sample
46
49
  ? new Set()
47
- : removablePaths(deps.db, projectId, keptPaths(deps.db, projectId));
50
+ : removablePaths(deps.db, projectId, new Set([...outputs, ...supplied]));
48
51
  let outputsBytes = 0;
49
52
  let workingBytes = 0;
50
53
  let removableFiles = 0;
51
54
  let removableBytes = 0;
52
- const history = sample ? new Set() : historyPaths(deps, projectId);
55
+ const history = sample ? new Set() : historyPaths(deps, projectId, supplied);
53
56
  let historyFiles = 0;
54
57
  let historyBytes = 0;
55
58
  for (const [path, bytes] of files) {
@@ -79,8 +82,7 @@ export function projectStorage(deps, projectId) {
79
82
  // Delete old versions: the files of older versions that arranging moved to History/, by their
80
83
  // stored paths. Never a file the user supplied, nor one they put in History themselves. Going
81
84
  // back to such a version makes its files again.
82
- function historyPaths(deps, projectId) {
83
- const supplied = suppliedPaths(deps.db, projectId);
85
+ function historyPaths(deps, projectId, supplied = suppliedPaths(deps.db, projectId)) {
84
86
  const out = new Set();
85
87
  for (const [path, place] of placedFiles(deps.paths, projectId))
86
88
  if (place.startsWith("History/") && !supplied.has(path))
@@ -248,14 +250,24 @@ function keptPaths(db, projectId) {
248
250
  }
249
251
  // The files the user supplied: nothing could make them again, so nothing removes them.
250
252
  function suppliedPaths(db, projectId) {
251
- const kept = new Set();
252
- for (const path of pathsOf(db
253
- .prepare(`SELECT a.path FROM project_assets a WHERE a.project_id=? AND (
254
- EXISTS(SELECT 1 FROM project_revisions r WHERE r.project_id=a.project_id
255
- AND (instr(r.content,a.id)>0 OR instr(r.config,a.id)>0))
256
- OR EXISTS(SELECT 1 FROM projects p WHERE p.id=a.project_id AND instr(p.config,a.id)>0))
257
- UNION SELECT path FROM outputs WHERE project_id=? AND original_filename IS NOT NULL`)
258
- .all(projectId, projectId)))
253
+ const kept = pathsOf(db
254
+ .prepare("SELECT path FROM outputs WHERE project_id=? AND original_filename IS NOT NULL")
255
+ .all(projectId));
256
+ const assets = db.prepare("SELECT id,path FROM project_assets WHERE project_id=?").all(projectId);
257
+ const texts = [];
258
+ const carry = (value) => {
259
+ if (typeof value === "string")
260
+ texts.push(value);
261
+ };
262
+ for (const row of db
263
+ .prepare("SELECT content,config FROM project_revisions WHERE project_id=?")
264
+ .all(projectId)) {
265
+ carry(row.content);
266
+ carry(row.config);
267
+ }
268
+ carry(db.prepare("SELECT config FROM projects WHERE id=?").get(projectId)?.config);
269
+ const named = idsNamedIn(assets.flatMap((row) => (typeof row.id === "string" ? [row.id] : [])), texts);
270
+ for (const path of pathsOf(assets.filter((row) => typeof row.id === "string" && named.has(row.id))))
259
271
  kept.add(path);
260
272
  return kept;
261
273
  }
@@ -1,3 +1,4 @@
1
+ import { outputsOf } from "../storage/repo.js";
1
2
  import { markUploaded } from "../uploads/repo.js";
2
3
  const taskState = (value) => value === "waiting" || value === "done" || value === "failed" ? value : "none";
3
4
  // A YouTube video id: 11 letters, digits, `-` and `_`.
@@ -12,6 +13,18 @@ export function videoIdOf(text) {
12
13
  return match?.[1];
13
14
  }
14
15
  const slot = (short) => short ?? 0;
16
+ // Every upload the project has is on YouTube: the long video, and each short it rendered
17
+ // (`short_video`, the outputs the pack lists). A project whose long video is up while a short
18
+ // still waits is not uploaded, so the short keeps its place in Ready to upload.
19
+ function allOnYoutube(db, projectId) {
20
+ if (videoOf(db, projectId, null)?.uploadState !== "done")
21
+ return false;
22
+ const shorts = new Set(outputsOf(db, projectId)
23
+ .filter((output) => output.role === "short_video")
24
+ .map((output) => output.meta.short)
25
+ .filter((number) => number !== undefined));
26
+ return [...shorts].every((number) => videoOf(db, projectId, number)?.uploadState === "done");
27
+ }
15
28
  function rowOf(row) {
16
29
  const short = Number(row.short);
17
30
  return {
@@ -42,7 +55,7 @@ export function recordVideo(db, projectId, short, videoId, at, state = "done") {
42
55
  upload_state=CASE WHEN video_id=excluded.video_id AND upload_state='done' THEN 'done'
43
56
  ELSE excluded.upload_state END,
44
57
  video_id=excluded.video_id, recorded_at=excluded.recorded_at`).run(projectId, slot(short), videoId, at, state);
45
- if (short === null && videoOf(db, projectId, null)?.uploadState === "done")
58
+ if (allOnYoutube(db, projectId))
46
59
  markUploaded(db, projectId, true, at);
47
60
  }
48
61
  // Studio said the upload was scheduled or published. False when no such upload was filled.
@@ -50,17 +63,18 @@ export function confirmUpload(db, projectId, short, videoId, at) {
50
63
  const confirmed = db
51
64
  .prepare("UPDATE youtube_videos SET upload_state='done' WHERE project_id=? AND short=? AND video_id=?")
52
65
  .run(projectId, slot(short), videoId).changes > 0;
53
- if (confirmed && short === null)
66
+ if (confirmed && allOnYoutube(db, projectId))
54
67
  markUploaded(db, projectId, true, at);
55
68
  return confirmed;
56
69
  }
57
- // Forgets the video an upload became (deleted on YouTube, or a wrong link). Forgetting a long
58
- // video that was on YouTube takes the project's uploaded mark off with it; an upload only
59
- // filled in Studio never set the mark, so forgetting it leaves a mark made by hand.
70
+ // Forgets the video an upload became (deleted on YouTube, or a wrong link). Forgetting one
71
+ // that was on YouTube - the long video or a short - takes the project's uploaded mark off with
72
+ // it, since the mark stands for all of them; an upload only filled in Studio never set the
73
+ // mark, so forgetting it leaves a mark made by hand.
60
74
  export function forgetVideo(db, projectId, short, at) {
61
75
  const was = videoOf(db, projectId, short);
62
76
  db.prepare("DELETE FROM youtube_videos WHERE project_id=? AND short=?").run(projectId, slot(short));
63
- if (short === null && was?.uploadState === "done")
77
+ if (was?.uploadState === "done" && !allOnYoutube(db, projectId))
64
78
  markUploaded(db, projectId, false, at);
65
79
  }
66
80
  // "Mark not uploaded" (Home, Projects): the long video's link goes with the mark, so the two
@@ -88,7 +88,8 @@ export function serializeAss(cues, style) {
88
88
  const name = style.fontName.replace(/[\p{Cc},]/gu, " ").trim();
89
89
  const placement = subtitlePlacement(style.position ?? "bottom", style.height);
90
90
  const position = `{\\an${placement.alignment}\\pos(${style.width / 2},${placement.y})}`;
91
- const header = `[Script Info]\nScriptType: v4.00+\nPlayResX: ${style.width}\nPlayResY: ${style.height}\nWrapStyle: 0\nScaledBorderAndShadow: yes\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\nStyle: Default,${name},${style.fontSize},${assColour(style.color, "&H00FFFFFF")},${assColour(style.color, "&H00FFFFFF")},${assColour(style.outlineColor, "&H00101010")},&H80000000,0,0,0,0,100,100,0,0,1,2.5,1,2,60,60,60,1\n\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`;
91
+ // YCbCr Matrix: without it, ffmpeg 7.1 and later draw the colours as BT.601 on a BT.709 picture.
92
+ const header = `[Script Info]\nScriptType: v4.00+\nPlayResX: ${style.width}\nPlayResY: ${style.height}\nYCbCr Matrix: TV.709\nWrapStyle: 0\nScaledBorderAndShadow: yes\n\n[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\nStyle: Default,${name},${style.fontSize},${assColour(style.color, "&H00FFFFFF")},${assColour(style.color, "&H00FFFFFF")},${assColour(style.outlineColor, "&H00101010")},&H80000000,0,0,0,0,100,100,0,0,1,2.5,1,2,60,60,60,1\n\n[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`;
92
93
  return (header +
93
94
  cues
94
95
  .map((cue) => `Dialogue: 0,${assStamp(cue.start)},${assStamp(cue.end)},Default,,0,0,0,,${position}${speakerAss(cue, style.speakers)}${assText(cue.text)}\n`)
@@ -21,6 +21,8 @@ color) {
21
21
  "ScriptType: v4.00+",
22
22
  `PlayResX: ${String(width)}`,
23
23
  `PlayResY: ${String(height)}`,
24
+ // Without it, ffmpeg 7.1 and later draw the colours as BT.601 on a BT.709 picture.
25
+ "YCbCr Matrix: TV.709",
24
26
  "WrapStyle: 0",
25
27
  "ScaledBorderAndShadow: yes",
26
28
  "",
@@ -1,11 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
- import { constants, copyFileSync, linkSync, mkdirSync, readdirSync, renameSync, rmSync, statfsSync, statSync, utimesSync, } from "node:fs";
2
+ import { constants, copyFileSync, linkSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statfsSync, statSync, utimesSync, } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
4
  // The clips of a project's last render, kept so the next render encodes only the clips that
5
5
  // changed. A clip is named by what went into its ffmpeg run: the binary, the arguments with
6
- // its own output left out, every input file as it is on disk, and its chapter-card script and
7
- // font. Any change to those is another name, so a clip is never reused for a picture it
8
- // would not have drawn.
6
+ // its own output left out, every input file as it is on disk, its chapter-card script and
7
+ // font, and, for a clip that draws its own captions, their script, fonts and portraits. Any
8
+ // change to those is another name, so a clip is never reused for a picture it would not have
9
+ // drawn.
9
10
  //
10
11
  // The folder is one per project under a hidden folder of Projects, the same disk as the
11
12
  // render's working folder so a clip is linked, not copied; storage reconcile and backups
@@ -18,13 +19,15 @@ const mostBytes = 30 * 1024 ** 3;
18
19
  // floor: the free space a disk keeps before the caches give way; a tenth of a small disk.
19
20
  const leastFree = 20 * 1024 ** 3;
20
21
  const leastFreeShare = 0.1;
21
- export function cacheKey(bin, args, output, extra = []) {
22
+ export function cacheKey(bin, args, output, extra = [],
23
+ // What stands in the key for an argument that is a file written anew for every render.
24
+ stand = new Map()) {
22
25
  const inputs = [];
23
26
  args.forEach((value, at) => {
24
27
  if (args[at - 1] === "-i")
25
- inputs.push(fileIdentity(value));
28
+ inputs.push(stand.get(value) ?? fileIdentity(value));
26
29
  });
27
- const named = args.map((value) => (value === output ? outputMark : value));
30
+ const named = args.map((value) => (value === output ? outputMark : (stand.get(value) ?? value)));
28
31
  return createHash("sha256")
29
32
  .update(JSON.stringify([version, bin, named, inputs, extra]))
30
33
  .digest("hex");
@@ -35,6 +38,11 @@ export function fileIdentity(path) {
35
38
  const stat = statSync(path, { throwIfNoEntry: false });
36
39
  return stat === undefined ? path : `${path}|${String(stat.size)}|${String(stat.mtimeMs)}`;
37
40
  }
41
+ // A file as a key part by what it holds: for one that a render writes anew each time, whose
42
+ // path and date would never be the same twice.
43
+ export function contentIdentity(path) {
44
+ return createHash("sha256").update(readFileSync(path)).digest("hex");
45
+ }
38
46
  // Puts the cached clip at `target`; false when there is none.
39
47
  export function reuseClip(dir, key, target) {
40
48
  const cached = join(dir, `${key}.mp4`);