Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
hkonsti committed Oct 7, 2024
1 parent 7df8177 commit 1e26625
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 44 deletions.
50 changes: 29 additions & 21 deletions packages/renderer/client/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export const render = async (
workerId: number,
totalNumOfWorkers: number,
hiddenFolderId: string,
projectRenderSettings: Required<RenderVideoUserProjectSettings>,
overwriteRenderSettings: RenderVideoUserProjectSettings,
) => {
try {
const renderer = new Renderer(project);

// Range calculation
const range =
overwriteRenderSettings.range ?? project.settings.shared.range;

const {firstGlobalFrame, lastGlobalFrame} =
await getGlobalFirstAndLastFrame(
project,
renderer,
projectRenderSettings.range[0],
projectRenderSettings.range[1],
);
await getGlobalFirstAndLastFrame(project, renderer, range[0], range[1]);

const {firstWorkerFrame, lastWorkerFrame} =
await getWorkerFirstAndLastFrame(
firstGlobalFrame,
Expand All @@ -42,29 +42,37 @@ export const render = async (
totalNumOfWorkers,
);

const fullRenderingSettings = getFullRenderingSettings(project);
const renderSettingsFromProject = getFullRenderingSettings(project);

// Overwrite settings with user provided settings
let background = renderSettingsFromProject.background;
if (overwriteRenderSettings.background) {
background = new Color(overwriteRenderSettings.background);
}

let size = renderSettingsFromProject.size;
if (overwriteRenderSettings.size) {
size = new Vector2(
overwriteRenderSettings.size.x,
overwriteRenderSettings.size.y,
);
}

const renderSettings = {
...fullRenderingSettings,
// Combine settings
const combinedSettings = {
...renderSettingsFromProject,
name: project.name,
hiddenFolderId: hiddenFolderId,
...projectRenderSettings,
...overwriteRenderSettings,
background,
size,
range: [
renderer.frameToTime(firstWorkerFrame),
renderer.frameToTime(lastWorkerFrame),
] as [number, number],
size: projectRenderSettings.size
? new Vector2(
projectRenderSettings.size.x,
projectRenderSettings.size.y,
)
: fullRenderingSettings.size,
background: projectRenderSettings.background
? new Color(projectRenderSettings.background)
: fullRenderingSettings.background,
};

await renderer.render(renderSettings);
await renderer.render(combinedSettings);
window.onRenderComplete();
} catch (e: any) {
window.onRenderFailed(e.message);
Expand Down
7 changes: 2 additions & 5 deletions packages/renderer/server/render-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import puppeteer, {Browser, PuppeteerLaunchOptions} from 'puppeteer';
import {
getParamDefaultsAndCheckValidity,
getRenderVideoUserProjectSettingsDefault,
} from 'validate-settings';
import {getParamDefaultsAndCheckValidity} from 'validate-settings';
import {InlineConfig, ServerOptions, ViteDevServer, createServer} from 'vite';
import {rendererPlugin} from './renderer-plugin';

Expand Down Expand Up @@ -96,7 +93,7 @@ async function initBrowserAndServer(
plugins: [
motionCanvas({project: resolvedProjectPath, output: outputFolderName}),
rendererPlugin(
getRenderVideoUserProjectSettingsDefault(settings.projectSettings),
settings.projectSettings,
variables,
settings.ffmpeg,
projectFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/server/renderer-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function escapeSpecialChars(_: string, value: string) {
}

export function rendererPlugin(
projectSettings: Required<RenderVideoUserProjectSettings>,
projectSettings?: RenderVideoUserProjectSettings,
variables?: Record<string, unknown>,
customFfmpegSettings?: FfmpegSettings,
projectFile?: string,
Expand Down
18 changes: 1 addition & 17 deletions packages/renderer/server/validate-settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
defaultUserProjectSettings,
FfmpegExporterOptions,
RenderVideoUserProjectSettings,
} from '@revideo/core';
import {FfmpegExporterOptions} from '@revideo/core';
import type {RenderSettings} from 'render-video';
import {v4 as uuidv4} from 'uuid';

Expand Down Expand Up @@ -102,15 +98,3 @@ export function getParamDefaultsAndCheckValidity(settings: RenderSettings): {
format: settings.projectSettings?.exporter?.options.format ?? 'mp4',
};
}

export function getRenderVideoUserProjectSettingsDefault(
settings?: RenderVideoUserProjectSettings,
): Required<RenderVideoUserProjectSettings> {
return {
range: defaultUserProjectSettings.shared.range,
background: defaultUserProjectSettings.shared.background,
size: defaultUserProjectSettings.shared.size,
exporter: defaultUserProjectSettings.rendering.exporter,
...settings,
};
}

0 comments on commit 1e26625

Please sign in to comment.