Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/src/commands/render/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export interface RenderPlan {
renderTarget: string;
fps: Fps;
quality: RenderQuality;
qualityPreset: keyof typeof QUALITY_ALIASES;
authoringSkill?: string;
invalidAuthoringSkill?: string;
/** Which resolution step provided authoringSkill: an explicit --skill flag, or the project's own config. */
Expand Down Expand Up @@ -638,6 +639,7 @@ export function createRenderPlan(args: RenderCommandArgs, now = new Date()): Ren
renderTarget,
fps,
quality,
qualityPreset: qualityRaw as keyof typeof QUALITY_ALIASES,
authoringSkill,
invalidAuthoringSkill,
authoringSkillSource,
Expand Down
45 changes: 45 additions & 0 deletions packages/cli/src/commands/render/present.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createRenderPlan, type RenderCommandArgs } from "./plan.js";
import { presentRenderPlan } from "./present.js";

describe("presentRenderPlan", () => {
let projectDir: string;
let printed: string[];

beforeEach(() => {
projectDir = mkdtempSync(join(tmpdir(), "hf-render-present-"));
writeFileSync(
join(projectDir, "index.html"),
'<main data-composition-id="main" data-width="1920" data-height="1080" data-fps="30"></main>',
);
printed = [];
vi.spyOn(console, "log").mockImplementation((line?: unknown) => {
printed.push(String(line ?? ""));
});
vi.spyOn(console, "error").mockImplementation(() => {});
});

afterEach(() => {
vi.restoreAllMocks();
rmSync(projectDir, { recursive: true, force: true });
});

async function settingsLine(args: Omit<RenderCommandArgs, "dir">): Promise<string | undefined> {
await presentRenderPlan(createRenderPlan({ dir: projectDir, workers: "2", ...args }));
return printed.find((line) => line.includes("2 workers"));
}

it.each([
[{}, "looks (CRF 16)"],
[{ quality: "draft" }, "draft"],
[{ quality: "standard" }, "standard"],
[{ quality: "delivery" }, "delivery"],
[{ crf: "20" }, "looks (CRF 20)"],
[{ "video-bitrate": "10M" }, "looks (10M)"],
])("names the quality it encodes with for %o", async (args, label) => {
expect(await settingsLine(args)).toContain(`30fps · ${label} · 2 workers`);
});
});
8 changes: 7 additions & 1 deletion packages/cli/src/commands/render/present.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function presentRenderSummary(plan: RenderPlan): void {
c.accent("\u25C6") + " Rendering " + c.accent(nameLabel) + c.dim(" \u2192 " + plan.outputPath),
);
console.log(
c.dim(` ${fpsToFfmpegArg(plan.fps)}fps \u00B7 ${plan.quality} \u00B7 ${workerLabel}`),
c.dim(` ${fpsToFfmpegArg(plan.fps)}fps \u00B7 ${qualityLabel(plan)} \u00B7 ${workerLabel}`),
);
if (plan.outputResolution) {
console.log(c.dim(" Output resolution: " + plan.outputResolution));
Expand All @@ -50,6 +50,12 @@ function presentRenderSummary(plan: RenderPlan): void {
console.log("");
}

function qualityLabel(plan: Pick<RenderPlan, "qualityPreset" | "crf" | "videoBitrate">): string {
if (plan.crf !== undefined) return `${plan.qualityPreset} (CRF ${plan.crf})`;
if (plan.videoBitrate) return `${plan.qualityPreset} (${plan.videoBitrate})`;
return plan.qualityPreset;
}

/** The GPU line's accelerated modes, or undefined when neither is. */
function formatGpuModes(plan: RenderPlan): string | undefined {
const modes: string[] = [];
Expand Down
Loading