@gentbajko/slopify 4.4.0 → 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/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.5.0.md +20 -0
- package/dist/patch-notes/index.json +6 -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/video/edit-settings.js +17 -0
- package/dist/slices/video/encoder-probe.js +124 -0
- package/dist/slices/video/encoding.js +143 -91
- package/dist/slices/video/ffmpeg.js +4 -2
- package/dist/slices/video/slideshow.js +32 -8
- package/dist/tutorials/Create-Video-and-Style.md +13 -0
- package/dist/tutorials/Settings-Reference.md +2 -0
- 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-CA_I2trg.js +0 -460
|
Binary file
|
|
Binary file
|
package/dist/main.js
CHANGED
|
@@ -119,7 +119,8 @@ import { storedUnknownAcks } from "./slices/template-studio/save.js";
|
|
|
119
119
|
import { notReadySentence, runnableTemplate, templateGate, } from "./slices/template-studio/schedule-gate.js";
|
|
120
120
|
import { createPriceCache } from "./slices/template-studio/service.js";
|
|
121
121
|
import { createTrashPurge } from "./slices/trash/service.js";
|
|
122
|
-
import { createNvencProbe,
|
|
122
|
+
import { createNvencProbe, createSvtAv1Probe } from "./slices/video/encoder-probe.js";
|
|
123
|
+
import { noNvenc, noSvtAv1, renderMachine } from "./slices/video/encoding.js";
|
|
123
124
|
import { probeDurationMs, runFfmpegAt } from "./slices/video/ffmpeg.js";
|
|
124
125
|
import { createRenderGate } from "./slices/video/render-gate.js";
|
|
125
126
|
import { watchActivation } from "./updater/candidate.js";
|
|
@@ -262,6 +263,13 @@ export async function boot(config, options = {}) {
|
|
|
262
263
|
exec: ffmpegOutput,
|
|
263
264
|
log,
|
|
264
265
|
});
|
|
266
|
+
// A project's Video codec AV1 on the processor: the bundled ffmpeg has no SVT-AV1, so the
|
|
267
|
+
// computer's own is asked, once, when a render first needs it.
|
|
268
|
+
const svtav1 = createSvtAv1Probe({
|
|
269
|
+
candidates: [ffmpeg, "ffmpeg", "/usr/bin/ffmpeg"],
|
|
270
|
+
exec: ffmpegOutput,
|
|
271
|
+
log,
|
|
272
|
+
});
|
|
265
273
|
// Settings → Production defaults → Render priority for the ffmpeg work outside a project's
|
|
266
274
|
// render (Template Studio's samples, designs' drawing, posts' pictures), read as each starts.
|
|
267
275
|
const renderPriority = () => readSettings({ db: runtimeDb, log }).renderPriority;
|
|
@@ -353,6 +361,7 @@ export async function boot(config, options = {}) {
|
|
|
353
361
|
catalogue,
|
|
354
362
|
ffmpeg,
|
|
355
363
|
nvenc,
|
|
364
|
+
svtav1,
|
|
356
365
|
audioPreviews,
|
|
357
366
|
});
|
|
358
367
|
const updateDb = db;
|
|
@@ -1071,7 +1080,7 @@ export async function boot(config, options = {}) {
|
|
|
1071
1080
|
throw error;
|
|
1072
1081
|
}
|
|
1073
1082
|
}
|
|
1074
|
-
export function wireRunner({ onFinished, audioPreviews, db, paths, clock, ids, log, hub, telemetry, flusher, registry, catalogue, ffmpeg, nvenc = async () => ({ available: false, reason: noNvenc }),
|
|
1083
|
+
export function wireRunner({ onFinished, audioPreviews, db, paths, clock, ids, log, hub, telemetry, flusher, registry, catalogue, ffmpeg, nvenc = async () => ({ available: false, reason: noNvenc }), svtav1 = async () => ({ available: false, reason: noSvtAv1 }),
|
|
1075
1084
|
// Settings → Production defaults → Subtitle timing model, read as each alignment starts.
|
|
1076
1085
|
alignSubtitles: aligner = alignSubtitlesWith(() => readSettings({ db, log }).subtitleModel),
|
|
1077
1086
|
// Settings → Production defaults → Videos rendered at once, read as each render asks for its
|
|
@@ -1093,7 +1102,7 @@ renderGate = createRenderGate(() => readSettings({ db, log }).videoRenderConcurr
|
|
|
1093
1102
|
ffmpeg,
|
|
1094
1103
|
alignSubtitles: aligner,
|
|
1095
1104
|
// Settings → Production defaults → Rendering, read as each render starts.
|
|
1096
|
-
renderMachine: (projectId) => renderMachine({ settings: readSettings({ db, log }), nvenc, log, projectId }),
|
|
1105
|
+
renderMachine: (projectId, codec) => renderMachine({ settings: readSettings({ db, log }), nvenc, svtav1, codec, log, projectId }),
|
|
1097
1106
|
// One queue for every render this computer makes, so a second video waits rather than
|
|
1098
1107
|
// taking the processor and memory the first one and the page are using.
|
|
1099
1108
|
renderGate,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Slopify 4.5.0
|
|
2
|
+
|
|
3
|
+
Released 18 November 2026.
|
|
4
|
+
|
|
5
|
+
Long videos now come out AV1 on an NVIDIA graphics card, about half the size of before for the same picture, and every template can choose its own video codec.
|
|
6
|
+
|
|
7
|
+
## Smaller videos: AV1 on the graphics card by default
|
|
8
|
+
|
|
9
|
+
- **The long video is now encoded as AV1 on the NVIDIA card wherever the card can do it,** whatever Settings → Production defaults → Video encoder says. Measured on a real 3-minute stretch of a 1080p video (slow pan and zoom over dense engraving), the card's AV1 file is about 44% of the size of the H.264 one for the same picture (about 94.4 VMAF against it).
|
|
10
|
+
- **Without a card, or on a card that can't encode AV1, nothing changes:** the video is made exactly as before, as H.264 through the Video encoder setting, and nothing is said about it.
|
|
11
|
+
- **If the card's AV1 encode fails mid-render,** the video is made again the old way.
|
|
12
|
+
- **No finished video turns outdated.** A video comes out AV1 the next time it is made for another reason.
|
|
13
|
+
|
|
14
|
+
## Choose a video codec per template
|
|
15
|
+
|
|
16
|
+
- **Video codec is a new setting in the Video section of Create, the template editor and Edit settings:** Automatic (the default: AV1 on the graphics card, else H.264), H.264, HEVC or AV1.
|
|
17
|
+
- **H.264** keeps a video exactly as before, never AV1.
|
|
18
|
+
- **HEVC and AV1** make a much smaller file. AV1 on the processor (SVT-AV1) is about 29% of the H.264 size but renders slower and needs an ffmpeg with SVT-AV1 on the computer; AV1 on the card is about 44%; HEVC on the card about 59%. HEVC on the processor (x265) is not measured yet.
|
|
19
|
+
- **A video is never failed for its codec.** When the chosen codec isn't available, the video is made as H.264 and the project's Video part says so and where to change it.
|
|
20
|
+
- **Only the long video changes.** Shorts and the style preview stay H.264, for the services shorts go to.
|
|
@@ -12,7 +12,7 @@ import { reviewModes, reviewStages } from "../reviews/model.js";
|
|
|
12
12
|
import { socialSettingsSchema } from "../social/schema.js";
|
|
13
13
|
import { subtitleConfigSchema } from "../subtitles/model.js";
|
|
14
14
|
import { ambientBedSchema } from "../video/ambient-bed-schema.js";
|
|
15
|
-
import { animateModes, atmospheres, colorGrades, cutModes, lookLevels, transitionKinds, } from "../video/edit-settings.js";
|
|
15
|
+
import { animateModes, atmospheres, colorGrades, cutModes, lookLevels, transitionKinds, videoCodecs, } from "../video/edit-settings.js";
|
|
16
16
|
import { voicesSettingsSchema } from "../voices/model.js";
|
|
17
17
|
import { entryModes, formats, motionStyles, referenceSources, runModes, stageSources, } from "./model.js";
|
|
18
18
|
import { defaultEdgeSilenceSeconds, defaultImageSeconds, defaultMotionStyle, defaultZoomPercent, } from "./rules.js";
|
|
@@ -35,6 +35,8 @@ export const videoEditSchema = z.object({
|
|
|
35
35
|
animate: z.enum(animateModes),
|
|
36
36
|
animateEvery: z.number(),
|
|
37
37
|
animateModel: z.string(),
|
|
38
|
+
// Absent is Automatic (`video/edit-settings.ts`).
|
|
39
|
+
codec: z.enum(videoCodecs).optional(),
|
|
38
40
|
});
|
|
39
41
|
// The shape Play posts and the shape `projects.config` holds, in one place: the second
|
|
40
42
|
// is the first plus the rendered prompt texts.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { fingerprint } from "../../kernel/runner/work.js";
|
|
3
3
|
import { usesYoutubeDescription } from "../admission/rules.js";
|
|
4
|
+
import { usesShortMode } from "../admission/short-mode.js";
|
|
4
5
|
import { headingChapters, topHeadings } from "../video/chapters.js";
|
|
5
6
|
import { chapterOpeningShots, sentenceCutPoints } from "../video/cuts.js";
|
|
6
|
-
import { animatedClipSeconds, animatedImageIndexes, animatePrompt, editNeedsTiming, usesAnimation, usesChapterCards, usesNarrationCuts, videoEditOf, } from "../video/edit-settings.js";
|
|
7
|
+
import { animatedClipSeconds, animatedImageIndexes, animatePrompt, editNeedsTiming, usesAnimation, usesChapterCards, usesNarrationCuts, videoCodecOf, videoEditOf, } from "../video/edit-settings.js";
|
|
7
8
|
import { fps } from "../video/plan.js";
|
|
8
9
|
import { recipe, resourceIdentity, selectedReference, } from "./recipe-model.js";
|
|
9
10
|
// What the Video stage's edit settings add to the plan: the word timing and chapters the
|
|
@@ -36,6 +37,12 @@ export function editPlan(context, exports, youtube, images, cards = []) {
|
|
|
36
37
|
edit.grade !== "none" ||
|
|
37
38
|
edit.atmosphere !== "none")
|
|
38
39
|
values.push(["look-v1", edit.vignette, edit.grain, edit.grade, edit.atmosphere]);
|
|
40
|
+
// Automatic and H.264 add nothing, so a project without a codec keeps its fingerprint: the
|
|
41
|
+
// next time it is made it simply comes out AV1 where the card can. A short-mode project
|
|
42
|
+
// renders as a short, which stays H.264.
|
|
43
|
+
const codec = videoCodecOf(config);
|
|
44
|
+
if ((codec === "hevc" || codec === "av1") && !usesShortMode(config))
|
|
45
|
+
values.push(["codec", codec]);
|
|
39
46
|
if (usesChapterCards(config))
|
|
40
47
|
values.push(["cards-v1", config.subtitles?.fontId ?? "default"]);
|
|
41
48
|
// The brand kit's end screen and title style; nothing when unset, so a project without them
|
|
@@ -10,6 +10,7 @@ import { allocateAsset, discardPreparedAssets, sealAsset } from "../storage/asse
|
|
|
10
10
|
import { outputPath, projectDir, renderCacheDir } from "../storage/layout.js";
|
|
11
11
|
import { audioExportArgs } from "../video/audio-export.js";
|
|
12
12
|
import { withPaths } from "../video/edit-list.js";
|
|
13
|
+
import { videoCodecOf } from "../video/edit-settings.js";
|
|
13
14
|
import { runFfmpeg } from "../video/ffmpeg.js";
|
|
14
15
|
import { planRender } from "../video/plan.js";
|
|
15
16
|
import { openRenderGate } from "../video/render-gate.js";
|
|
@@ -24,8 +25,8 @@ import { lineLevelledAudio } from "./runtime-lines.js";
|
|
|
24
25
|
import { preparedResult, preparedText, publishResult } from "./runtime-publication.js";
|
|
25
26
|
import { pieceAlreadyDone } from "./work-records.js";
|
|
26
27
|
// The machine settings for one render, and the notices it gathers for the project page.
|
|
27
|
-
export async function exportMachine(deps, projectId) {
|
|
28
|
-
const chosen = await deps.renderMachine?.(projectId);
|
|
28
|
+
export async function exportMachine(deps, projectId, codec = "h264") {
|
|
29
|
+
const chosen = await deps.renderMachine?.(projectId, codec);
|
|
29
30
|
const notices = chosen?.notice === undefined ? [] : [chosen.notice];
|
|
30
31
|
return {
|
|
31
32
|
machine: chosen?.machine,
|
|
@@ -134,7 +135,7 @@ export async function executeExportRecipe(deps, context, piece) {
|
|
|
134
135
|
};
|
|
135
136
|
if (!context.maySubmit(piece.id))
|
|
136
137
|
return "held";
|
|
137
|
-
const machine = await exportMachine(deps, context.work.projectId);
|
|
138
|
+
const machine = await exportMachine(deps, context.work.projectId, plan === undefined ? "h264" : videoCodecOf(config));
|
|
138
139
|
const priority = machine.machine?.priority;
|
|
139
140
|
const onProgress = (elapsedMs) => context.emit({
|
|
140
141
|
type: "stage.progress",
|
|
@@ -17,6 +17,12 @@ export const colorGrades = ["none", "warm", "cold", "desaturated", "sepia"];
|
|
|
17
17
|
// Drawn procedurally by ffmpeg's own filters (`look.ts`); no third-party footage.
|
|
18
18
|
export const atmospheres = ["none", "embers", "dust", "fog"];
|
|
19
19
|
export const animateModes = ["off", "chapters", "every"];
|
|
20
|
+
// The finished video's codec. How it is encoded (processor or NVIDIA card) is the computer's
|
|
21
|
+
// choice (`encoding.ts`); this is the project's, since it changes the file. The stored values
|
|
22
|
+
// are the explicit choices; no value at all is Automatic: AV1 on an NVIDIA card that can
|
|
23
|
+
// encode it, else H.264 exactly as before.
|
|
24
|
+
export const videoCodecs = ["h264", "hevc", "av1"];
|
|
25
|
+
export const videoCodecChoices = ["auto", ...videoCodecs];
|
|
20
26
|
export const legacyVideoEdit = {
|
|
21
27
|
cuts: "interval",
|
|
22
28
|
transition: "cut",
|
|
@@ -86,6 +92,16 @@ export const animateModeLabels = {
|
|
|
86
92
|
chapters: "Chapter openers",
|
|
87
93
|
every: "Every Nth image",
|
|
88
94
|
};
|
|
95
|
+
export const videoCodecLabels = {
|
|
96
|
+
auto: "Automatic (AV1 on the graphics card, else H.264)",
|
|
97
|
+
h264: "H.264",
|
|
98
|
+
hevc: "HEVC",
|
|
99
|
+
av1: "AV1",
|
|
100
|
+
};
|
|
101
|
+
export const videoCodecHelp = "Automatic uses AV1 on an NVIDIA card that can encode it, else H.264. H.264 works everywhere. HEVC and AV1 make about half to a third of the file for the same picture; AV1 on the processor needs an ffmpeg with SVT-AV1 and renders slower.";
|
|
102
|
+
export function videoCodecOf(config) {
|
|
103
|
+
return config.videoEdit?.codec ?? "auto";
|
|
104
|
+
}
|
|
89
105
|
// The settings a project renders with: its own, or today's behaviour when it has none.
|
|
90
106
|
export function videoEditOf(config) {
|
|
91
107
|
return config.videoEdit ?? legacyVideoEdit;
|
|
@@ -186,6 +202,7 @@ export function videoEditRows(edit) {
|
|
|
186
202
|
? animateModeLabels.off
|
|
187
203
|
: `${edit.animate === "every" ? `Every ${nth(edit.animateEvery)} image` : animateModeLabels.chapters}${edit.animateModel.trim() === "" ? "" : ` · ${edit.animateModel}`}`,
|
|
188
204
|
],
|
|
205
|
+
["Video codec", videoCodecLabels[edit.codec ?? "auto"]],
|
|
189
206
|
];
|
|
190
207
|
}
|
|
191
208
|
// Which images of the slideshow order (0-based) are animated: every Nth from the first, or
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { errorText } from "../../kernel/errors.js";
|
|
2
|
+
import { videoCodecLabels } from "./edit-settings.js";
|
|
3
|
+
import { codecArgs, noNvenc, noSvtAv1 } from "./encoding.js";
|
|
4
|
+
export const failedNvenc = "No working NVIDIA graphics card was found on this computer.";
|
|
5
|
+
const failedSvtAv1 = "No working ffmpeg with SVT-AV1 (libsvtav1) was found on this computer.";
|
|
6
|
+
// The renders' own settings on a tiny picture: a driver or card that refuses any of them fails
|
|
7
|
+
// here rather than in a render. NVENC refuses anything under about 145 pixels across.
|
|
8
|
+
function testArgs(encode) {
|
|
9
|
+
return [
|
|
10
|
+
"-hide_banner",
|
|
11
|
+
"-nostdin",
|
|
12
|
+
"-loglevel",
|
|
13
|
+
"error",
|
|
14
|
+
"-f",
|
|
15
|
+
"lavfi",
|
|
16
|
+
"-i",
|
|
17
|
+
"color=c=black:s=256x256:r=30:d=0.1",
|
|
18
|
+
"-frames:v",
|
|
19
|
+
"1",
|
|
20
|
+
...codecArgs(encode, "final", undefined),
|
|
21
|
+
"-f",
|
|
22
|
+
"null",
|
|
23
|
+
"-",
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
// The filters a render runs in the computer's ffmpeg besides the encoder.
|
|
27
|
+
const neededFilters = ["zoompan", "perspective", "fillborders", "xfade", "ass"];
|
|
28
|
+
// Which ffmpeg can encode on an NVIDIA card. The bundled ffmpeg first, then the computer's own:
|
|
29
|
+
// unlike everything else, NVENC is the computer's (its driver and its ffmpeg), and only used
|
|
30
|
+
// when chosen in Settings. Asked for HEVC or AV1, the card that passed for H.264 is tested again
|
|
31
|
+
// with that codec's encoder, since older cards have no AV1 and the oldest no HEVC.
|
|
32
|
+
export function createNvencProbe(deps) {
|
|
33
|
+
const answers = new Map();
|
|
34
|
+
const ask = (codec) => {
|
|
35
|
+
let answer = answers.get(codec);
|
|
36
|
+
if (answer === undefined) {
|
|
37
|
+
answer = (codec === "h264"
|
|
38
|
+
? probe(deps, {
|
|
39
|
+
label: "NVENC",
|
|
40
|
+
encoders: ["h264_nvenc"],
|
|
41
|
+
test: (bin) => testArgs({ kind: "nvenc", bin, clipSpeed: "thorough" }),
|
|
42
|
+
none: noNvenc,
|
|
43
|
+
failed: failedNvenc,
|
|
44
|
+
})
|
|
45
|
+
: ask("h264").then((card) => cardCodec(deps, card, codec))).catch((error) => ({
|
|
46
|
+
available: false,
|
|
47
|
+
reason: noNvenc,
|
|
48
|
+
detail: errorText(error),
|
|
49
|
+
}));
|
|
50
|
+
answers.set(codec, answer);
|
|
51
|
+
}
|
|
52
|
+
return answer;
|
|
53
|
+
};
|
|
54
|
+
return (codec = "h264") => ask(codec);
|
|
55
|
+
}
|
|
56
|
+
async function cardCodec(deps, card, codec) {
|
|
57
|
+
if (!card.available)
|
|
58
|
+
return card;
|
|
59
|
+
try {
|
|
60
|
+
await deps.exec(card.bin, testArgs({ kind: "nvenc", bin: card.bin, clipSpeed: "thorough", codec }));
|
|
61
|
+
return card;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const detail = `the ${codec}_nvenc test encode through ${card.bin} failed: ${errorText(error)}`;
|
|
65
|
+
deps.log.write("info", "video.encoder", { detail });
|
|
66
|
+
return {
|
|
67
|
+
available: false,
|
|
68
|
+
reason: `This NVIDIA graphics card can't encode ${videoCodecLabels[codec]}.`,
|
|
69
|
+
detail,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Which ffmpeg encodes AV1 on the processor with SVT-AV1. It also encodes the clips that are
|
|
74
|
+
// decoded again under captions, which stay H.264, so it needs x264 as well.
|
|
75
|
+
export function createSvtAv1Probe(deps) {
|
|
76
|
+
let answer;
|
|
77
|
+
return () => {
|
|
78
|
+
answer ??= probe(deps, {
|
|
79
|
+
label: "SVT-AV1",
|
|
80
|
+
encoders: ["libsvtav1", "libx264"],
|
|
81
|
+
test: (bin) => testArgs({ kind: "svtav1", bin, clipSpeed: "thorough" }),
|
|
82
|
+
none: noSvtAv1,
|
|
83
|
+
failed: failedSvtAv1,
|
|
84
|
+
}).catch((error) => ({
|
|
85
|
+
available: false,
|
|
86
|
+
reason: noSvtAv1,
|
|
87
|
+
detail: errorText(error),
|
|
88
|
+
}));
|
|
89
|
+
return answer;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function probe(deps, want) {
|
|
93
|
+
const listed = (output, name) => new RegExp(`^\\s*V\\S*\\s+${name}\\s`, "m").test(output);
|
|
94
|
+
let failed;
|
|
95
|
+
for (const bin of new Set(deps.candidates)) {
|
|
96
|
+
const encoders = await deps.exec(bin, ["-hide_banner", "-encoders"]).catch(() => "");
|
|
97
|
+
if (!listed(encoders, want.encoders[0]))
|
|
98
|
+
continue;
|
|
99
|
+
const lacking = want.encoders.slice(1).filter((name) => !listed(encoders, name));
|
|
100
|
+
if (lacking.length > 0) {
|
|
101
|
+
failed = `the ffmpeg at ${bin} has ${want.label} but not the ${lacking.join(", ")} encoder a video needs`;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const filters = await deps.exec(bin, ["-hide_banner", "-filters"]).catch(() => "");
|
|
105
|
+
const missing = neededFilters.filter((name) => !new RegExp(`^\\s*\\S+\\s+${name}\\s`, "m").test(filters));
|
|
106
|
+
if (missing.length > 0) {
|
|
107
|
+
failed = `the ffmpeg at ${bin} has ${want.label} but not the ${missing.join(", ")} filter a video needs`;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
await deps.exec(bin, want.test(bin));
|
|
112
|
+
deps.log.write("info", "video.encoder", { detail: `${want.label} works through ${bin}` });
|
|
113
|
+
return { available: true, bin };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
failed = `the ffmpeg at ${bin} lists ${want.label} but its test encode failed: ${errorText(error)}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (failed !== undefined) {
|
|
120
|
+
deps.log.write("info", "video.encoder", { detail: failed });
|
|
121
|
+
return { available: false, reason: want.failed, detail: failed };
|
|
122
|
+
}
|
|
123
|
+
return { available: false, reason: want.none };
|
|
124
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { constants, setPriority } from "node:os";
|
|
2
2
|
import { errorText } from "../../kernel/errors.js";
|
|
3
3
|
import { bt709Tags } from "./colour.js";
|
|
4
|
+
import { videoCodecLabels } from "./edit-settings.js";
|
|
4
5
|
import { lookEncoding } from "./look.js";
|
|
5
6
|
// Settings → Production defaults → Rendering: how this computer encodes a video's picture.
|
|
6
7
|
// They change how a video is made, never what it is, so no recipe fingerprint carries them and
|
|
7
|
-
// a render reads them once as it starts (`renderMachine`).
|
|
8
|
+
// a render reads them once as it starts (`renderMachine`). The finished video's codec is the
|
|
9
|
+
// project's (`edit-settings.ts`), and combines with them here.
|
|
8
10
|
export const videoEncoders = ["cpu", "nvidia"];
|
|
9
11
|
export const clipEncodeSpeeds = ["thorough", "fast"];
|
|
10
12
|
export const renderPriorities = ["normal", "background"];
|
|
@@ -24,20 +26,39 @@ const intermediateCrf = "16";
|
|
|
24
26
|
// size CRF 23 does, where NVENC scores about 2.5 VMAF below x264 (no NVENC setting tried closed
|
|
25
27
|
// that gap at that size).
|
|
26
28
|
export const nvencQuality = { intermediate: 20, final: 28.5 };
|
|
29
|
+
// measured on a real 3-minute stretch of a 1080p30 video, slow pan and zoom over dense
|
|
30
|
+
// engraving, each scoring about 94.4 VMAF against the H.264 file x264 makes today: SVT-AV1 at
|
|
31
|
+
// preset 6, CRF 36 is about 29% of its size at about 7x real time on 32 threads; av1_nvenc at
|
|
32
|
+
// CQ 34 about 44%; hevc_nvenc at CQ 27 about 59%. x265 at CRF 26 (preset medium) is not
|
|
33
|
+
// measured yet: a starting point expected to land near the same quality.
|
|
34
|
+
export const codecQuality = {
|
|
35
|
+
svtav1Preset: 6,
|
|
36
|
+
svtav1Crf: 36,
|
|
37
|
+
av1Nvenc: 34,
|
|
38
|
+
hevcNvenc: 27,
|
|
39
|
+
x265Crf: 26,
|
|
40
|
+
};
|
|
27
41
|
// measured on the first 24 shots of a real project, each still shown once (11.5 minutes, 32
|
|
28
42
|
// threads, changelog.d/2026-11-13-one-encode.md): clips that draw their own captions took
|
|
29
43
|
// 83 s at x264's default preset and 69 s at `faster`, for 1.2 VMAF less. That is the step
|
|
30
44
|
// Fast already was for clips encoded twice (118 s against 145 s, 0.7 VMAF less). `veryfast`
|
|
31
45
|
// cost 4.3 VMAF.
|
|
32
46
|
const captionedFastPreset = "faster";
|
|
47
|
+
// x264's own keyframe interval, so every clip, whatever its codec, opens on its one keyframe as
|
|
48
|
+
// x264's do and the clips still join by copying.
|
|
49
|
+
const keyframes = ["-g", "250"];
|
|
50
|
+
// HEVC in MP4 tagged hvc1 rather than hev1, which Apple's players and some browsers refuse.
|
|
51
|
+
const hvc1 = ["-tag:v", "hvc1"];
|
|
33
52
|
// `final` is a picture someone watches (a clip joined by copying, a burned-in part, the join);
|
|
34
|
-
// `intermediate` is a clip decoded again under burned-in captions
|
|
35
|
-
// draws its own captions, watched
|
|
53
|
+
// `intermediate` is a clip decoded again under burned-in captions, never watched, so it stays
|
|
54
|
+
// H.264 whatever the video's codec; `captioned` is a clip that draws its own captions, watched
|
|
55
|
+
// as it is.
|
|
36
56
|
export function codecArgs(encode, role, look) {
|
|
37
|
-
if (encode.kind === "nvenc")
|
|
57
|
+
if (encode.kind === "nvenc") {
|
|
58
|
+
const codec = role === "intermediate" ? undefined : encode.codec;
|
|
38
59
|
return [
|
|
39
60
|
"-c:v",
|
|
40
|
-
"
|
|
61
|
+
`${codec ?? "h264"}_nvenc`,
|
|
41
62
|
// The slowest, best preset, constant quality with no bitrate cap. No `-multipass`: measured,
|
|
42
63
|
// a second full-resolution pass gave no better picture for its size on these videos.
|
|
43
64
|
"-preset",
|
|
@@ -47,17 +68,51 @@ export function codecArgs(encode, role, look) {
|
|
|
47
68
|
"-rc",
|
|
48
69
|
"vbr",
|
|
49
70
|
"-cq",
|
|
50
|
-
String(
|
|
71
|
+
String(codec === "hevc"
|
|
72
|
+
? codecQuality.hevcNvenc
|
|
73
|
+
: codec === "av1"
|
|
74
|
+
? codecQuality.av1Nvenc
|
|
75
|
+
: nvencQuality[role === "intermediate" ? "intermediate" : "final"]),
|
|
51
76
|
"-b:v",
|
|
52
77
|
"0",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"-g",
|
|
56
|
-
"250",
|
|
78
|
+
...keyframes,
|
|
79
|
+
...(codec === "hevc" ? hvc1 : []),
|
|
57
80
|
"-pix_fmt",
|
|
58
81
|
"yuv420p",
|
|
59
82
|
...bt709Tags,
|
|
60
83
|
];
|
|
84
|
+
}
|
|
85
|
+
if (encode.kind === "x265" || encode.kind === "svtav1") {
|
|
86
|
+
if (role === "intermediate")
|
|
87
|
+
return codecArgs({ kind: "x264", clipSpeed: encode.clipSpeed }, role, look);
|
|
88
|
+
const common = ["-pix_fmt", "yuv420p", ...bt709Tags];
|
|
89
|
+
return encode.kind === "x265"
|
|
90
|
+
? [
|
|
91
|
+
"-c:v",
|
|
92
|
+
"libx265",
|
|
93
|
+
...common,
|
|
94
|
+
...lookEncoding(look),
|
|
95
|
+
"-preset",
|
|
96
|
+
"medium",
|
|
97
|
+
"-crf",
|
|
98
|
+
String(codecQuality.x265Crf),
|
|
99
|
+
...keyframes,
|
|
100
|
+
...hvc1,
|
|
101
|
+
// x265 reports every frame's statistics on stderr otherwise.
|
|
102
|
+
"-x265-params",
|
|
103
|
+
"log-level=error",
|
|
104
|
+
]
|
|
105
|
+
: [
|
|
106
|
+
"-c:v",
|
|
107
|
+
"libsvtav1",
|
|
108
|
+
...common,
|
|
109
|
+
"-preset",
|
|
110
|
+
String(codecQuality.svtav1Preset),
|
|
111
|
+
"-crf",
|
|
112
|
+
String(codecQuality.svtav1Crf),
|
|
113
|
+
...keyframes,
|
|
114
|
+
];
|
|
115
|
+
}
|
|
61
116
|
const fast = encode.clipSpeed === "fast";
|
|
62
117
|
return [
|
|
63
118
|
"-c:v",
|
|
@@ -73,103 +128,100 @@ export function codecArgs(encode, role, look) {
|
|
|
73
128
|
: []),
|
|
74
129
|
];
|
|
75
130
|
}
|
|
131
|
+
// What the join adds when it copies the clips: copying keeps the codec but not its MP4 tag.
|
|
132
|
+
export function copyTag(encode) {
|
|
133
|
+
return encode.kind === "x265" || (encode.kind === "nvenc" && encode.codec === "hevc") ? hvc1 : [];
|
|
134
|
+
}
|
|
135
|
+
// The ffmpeg that encodes the picture: the computer's own for NVENC and SVT-AV1, else the
|
|
136
|
+
// bundled one.
|
|
137
|
+
export function encoderBin(encode, bundled) {
|
|
138
|
+
return encode.kind === "nvenc" || encode.kind === "svtav1" ? encode.bin : bundled;
|
|
139
|
+
}
|
|
76
140
|
// Said to a person who may have no NVIDIA card at all: stock ffmpeg builds list the NVIDIA
|
|
77
141
|
// encoder everywhere, so a failed test usually means there is no card, not a broken one. What
|
|
78
142
|
// the test printed goes under Details (`detail`), never into these sentences.
|
|
79
143
|
export const noNvenc = "No NVIDIA graphics card was found on this computer.";
|
|
80
|
-
export const
|
|
144
|
+
export const noSvtAv1 = "No ffmpeg with SVT-AV1 (libsvtav1) was found on this computer.";
|
|
81
145
|
// The reason with the test's output, for the log and a run's notice.
|
|
82
146
|
export function nvencWhy(status) {
|
|
83
147
|
return status.detail === undefined ? status.reason : `${status.reason} (${status.detail})`;
|
|
84
148
|
}
|
|
85
|
-
// The
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"-loglevel",
|
|
91
|
-
"error",
|
|
92
|
-
"-f",
|
|
93
|
-
"lavfi",
|
|
94
|
-
"-i",
|
|
95
|
-
"color=c=black:s=256x256:r=30:d=0.1",
|
|
96
|
-
"-frames:v",
|
|
97
|
-
"1",
|
|
98
|
-
...codecArgs({ kind: "nvenc", bin: "", clipSpeed: "thorough" }, "final", undefined),
|
|
99
|
-
"-f",
|
|
100
|
-
"null",
|
|
101
|
-
"-",
|
|
102
|
-
];
|
|
103
|
-
// The filters a render runs in the NVENC ffmpeg besides the encoder.
|
|
104
|
-
const neededFilters = ["zoompan", "perspective", "fillborders", "xfade", "ass"];
|
|
105
|
-
// Which ffmpeg can encode on an NVIDIA card, asked once and remembered until Slopify restarts.
|
|
106
|
-
// The bundled ffmpeg first, then the computer's own: unlike everything else, NVENC is the
|
|
107
|
-
// computer's (its driver and its ffmpeg), and only used when chosen in Settings.
|
|
108
|
-
export function createNvencProbe(deps) {
|
|
109
|
-
let answer;
|
|
110
|
-
return () => {
|
|
111
|
-
answer ??= probe(deps).catch((error) => ({
|
|
112
|
-
available: false,
|
|
113
|
-
reason: noNvenc,
|
|
114
|
-
detail: errorText(error),
|
|
115
|
-
}));
|
|
116
|
-
return answer;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async function probe(deps) {
|
|
120
|
-
let failed;
|
|
121
|
-
for (const bin of new Set(deps.candidates)) {
|
|
122
|
-
const encoders = await deps.exec(bin, ["-hide_banner", "-encoders"]).catch(() => "");
|
|
123
|
-
if (!/^\s*V\S*\s+h264_nvenc\s/m.test(encoders))
|
|
124
|
-
continue;
|
|
125
|
-
const filters = await deps.exec(bin, ["-hide_banner", "-filters"]).catch(() => "");
|
|
126
|
-
const missing = neededFilters.filter((name) => !new RegExp(`^\\s*\\S+\\s+${name}\\s`, "m").test(filters));
|
|
127
|
-
if (missing.length > 0) {
|
|
128
|
-
failed = `the ffmpeg at ${bin} has NVENC but not the ${missing.join(", ")} filter a video needs`;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
await deps.exec(bin, testArgs);
|
|
133
|
-
deps.log.write("info", "video.encoder", { detail: `NVENC works through ${bin}` });
|
|
134
|
-
return { available: true, bin };
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
failed = `the ffmpeg at ${bin} lists NVENC but its test encode failed: ${errorText(error)}`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (failed !== undefined) {
|
|
141
|
-
deps.log.write("info", "video.encoder", { detail: failed });
|
|
142
|
-
return { available: false, reason: failedNvenc, detail: failed };
|
|
143
|
-
}
|
|
144
|
-
return { available: false, reason: noNvenc };
|
|
145
|
-
}
|
|
146
|
-
// The render's machine settings, read as it starts. A card chosen but not working is a notice,
|
|
147
|
-
// never a failed render: the processor encodes it instead.
|
|
149
|
+
// The render's machine settings, read as it starts. Automatic is AV1 on the NVIDIA card
|
|
150
|
+
// whenever the card can encode it, whatever the Video encoder says, with today's H.264 as its
|
|
151
|
+
// `fallback`; without such a card it is today's H.264 render, said nowhere, since that is the
|
|
152
|
+
// ordinary way. An explicit encoder or codec chosen but not working is a notice, never a
|
|
153
|
+
// failed render: the processor encodes it instead, or H.264 does.
|
|
148
154
|
export async function renderMachine(deps) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
if (deps.codec !== "auto")
|
|
156
|
+
return chosenMachine({ ...deps, codec: deps.codec ?? "h264" });
|
|
157
|
+
const today = await chosenMachine({ ...deps, codec: "h264" });
|
|
158
|
+
const card = await deps.nvenc();
|
|
159
|
+
if (!card.available)
|
|
160
|
+
return today;
|
|
161
|
+
const av1 = await deps.nvenc("av1");
|
|
162
|
+
if (!av1.available)
|
|
163
|
+
return today;
|
|
164
|
+
return {
|
|
165
|
+
machine: {
|
|
166
|
+
encode: {
|
|
167
|
+
kind: "nvenc",
|
|
168
|
+
bin: av1.bin,
|
|
169
|
+
clipSpeed: deps.settings.clipEncodeSpeed,
|
|
170
|
+
codec: "av1",
|
|
159
171
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
priority: deps.settings.renderPriority,
|
|
173
|
+
fallback: today.machine.encode,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async function chosenMachine(deps) {
|
|
178
|
+
const { settings, codec } = deps;
|
|
179
|
+
const clipSpeed = settings.clipEncodeSpeed;
|
|
180
|
+
const warn = (detail) => deps.log.write("warn", "video.encoder", { projectId: deps.projectId, detail });
|
|
181
|
+
const done = (chosen) => ({
|
|
182
|
+
machine: { encode: chosen.encode, priority: settings.renderPriority },
|
|
183
|
+
...(chosen.notices.length === 0 ? {} : { notice: chosen.notices.join(" ") }),
|
|
164
184
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
185
|
+
const cpu = async () => {
|
|
186
|
+
if (codec === "h264")
|
|
187
|
+
return { encode: { kind: "x264", clipSpeed }, notices: [] };
|
|
188
|
+
if (codec === "hevc")
|
|
189
|
+
return { encode: { kind: "x265", clipSpeed }, notices: [] };
|
|
190
|
+
const svt = (await deps.svtav1?.()) ?? { available: false, reason: noSvtAv1 };
|
|
191
|
+
if (svt.available)
|
|
192
|
+
return { encode: { kind: "svtav1", bin: svt.bin, clipSpeed }, notices: [] };
|
|
193
|
+
warn(`AV1 chosen but SVT-AV1 is unavailable; encoding H.264. ${nvencWhy(svt)}`);
|
|
194
|
+
return { encode: { kind: "x264", clipSpeed }, notices: [svtav1FallbackNotice(nvencWhy(svt))] };
|
|
168
195
|
};
|
|
196
|
+
if (settings.videoEncoder !== "nvidia")
|
|
197
|
+
return done(await cpu());
|
|
198
|
+
const card = await deps.nvenc();
|
|
199
|
+
if (!card.available) {
|
|
200
|
+
warn(`NVIDIA encoder chosen but unavailable; encoding on the processor. ${nvencWhy(card)}`);
|
|
201
|
+
const chosen = await cpu();
|
|
202
|
+
return done({
|
|
203
|
+
encode: chosen.encode,
|
|
204
|
+
notices: [nvencFallbackNotice(nvencWhy(card)), ...chosen.notices],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const h264 = { kind: "nvenc", bin: card.bin, clipSpeed };
|
|
208
|
+
if (codec === "h264")
|
|
209
|
+
return done({ encode: h264, notices: [] });
|
|
210
|
+
const own = await deps.nvenc(codec);
|
|
211
|
+
if (own.available)
|
|
212
|
+
return done({ encode: { ...h264, bin: own.bin, codec }, notices: [] });
|
|
213
|
+
warn(`${videoCodecLabels[codec]} on the NVIDIA card is unavailable; encoding H.264 on it.`);
|
|
214
|
+
return done({ encode: h264, notices: [cardCodecNotice(codec, nvencWhy(own))] });
|
|
169
215
|
}
|
|
170
216
|
export function nvencFallbackNotice(reason) {
|
|
171
217
|
return `This video was encoded on the processor because the NVIDIA graphics card encoder didn't work (${reason.replace(/\.$/, "")}). Check the NVIDIA driver, or choose Processor (x264) in Settings → Production defaults → Video encoder.`;
|
|
172
218
|
}
|
|
219
|
+
export function svtav1FallbackNotice(reason) {
|
|
220
|
+
return `This video was encoded as H.264 instead of AV1 because AV1 on the processor needs an ffmpeg with SVT-AV1 (${reason.replace(/\.$/, "")}). Install an ffmpeg built with SVT-AV1 and restart Slopify, or choose H.264 or HEVC under Video codec in the project's Video settings.`;
|
|
221
|
+
}
|
|
222
|
+
function cardCodecNotice(codec, reason) {
|
|
223
|
+
return `This video was encoded as H.264 on the NVIDIA graphics card because it couldn't encode ${videoCodecLabels[codec]} (${reason.replace(/\.$/, "")}). Choose H.264${codec === "av1" ? " or HEVC" : ""} under Video codec in the project's Video settings, or Processor in Settings → Production defaults → Video encoder.`;
|
|
224
|
+
}
|
|
173
225
|
// Background renders run below normal priority: nice 10 on Linux and macOS, the below-normal
|
|
174
226
|
// class on Windows. Threads ffmpeg starts afterwards inherit it. Advisory: a system that
|
|
175
227
|
// refuses is logged and the render carries on.
|
|
@@ -3,7 +3,7 @@ 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
5
|
import { bt709Frames, bt709Scale } from "./colour.js";
|
|
6
|
-
import { codecArgs, defaultEncode, setRenderPriority, } from "./encoding.js";
|
|
6
|
+
import { codecArgs, copyTag, defaultEncode, setRenderPriority, } from "./encoding.js";
|
|
7
7
|
import { gradeFilter, lookChain, placed } from "./look.js";
|
|
8
8
|
import { moveOf } from "./move.js";
|
|
9
9
|
import { decimal } from "./plan.js";
|
|
@@ -295,7 +295,9 @@ export function joinArgs(edit, output, list, burnSubtitles = false, portraits =
|
|
|
295
295
|
"-map",
|
|
296
296
|
burnSubtitles ? "[v]" : "0:v",
|
|
297
297
|
...(audio ? ["-map", sound === undefined ? "[a]" : "1:a"] : []),
|
|
298
|
-
...(burnSubtitles
|
|
298
|
+
...(burnSubtitles
|
|
299
|
+
? codecArgs(encode, "final", edit.look)
|
|
300
|
+
: ["-c:v", "copy", ...copyTag(encode)]),
|
|
299
301
|
...(audio ? ["-c:a", sound === undefined ? "aac" : "copy"] : ["-an"]),
|
|
300
302
|
"-movflags",
|
|
301
303
|
"+faststart",
|