Skip to content

Commit

Permalink
chore: resolve lots of type stuff, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hkonsti committed Oct 7, 2024
1 parent 0e7e4d5 commit 73e8574
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 193 deletions.
7 changes: 1 addition & 6 deletions packages/core/src/app/Project.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
FfmpegExporterOptions,
ImageExporterOptions,
WasmExporterOptions,
} from '../exporter';
import {FfmpegExporterOptions, ImageExporterOptions} from '../exporter';
import type {Plugin} from '../plugin';
import {SceneDescription} from '../scenes';
import {CanvasColorSpace, Color, Vector2} from '../types';
Expand Down Expand Up @@ -36,7 +32,6 @@ export type ExporterSettings =
}
| {
name: '@revideo/core/wasm';
options: WasmExporterOptions;
};

export interface ProjectSettings {
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/app/makeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export function makeProject(project: UserProject): Project {
rendering: {
exporter: {
name: '@revideo/core/wasm',
options: {
format: 'mp4',
},
},
fps: 30,
resolutionScale: 1,
Expand All @@ -36,7 +33,7 @@ export function makeProject(project: UserProject): Project {
},
};

const settings: UserProjectSettings = {
const settings = {
...defaultSettings,
...project.settings,
shared: {
Expand All @@ -53,19 +50,20 @@ export function makeProject(project: UserProject): Project {
},
};

const modifiedSettings = {
// Convert background and size to correct types
const convertedSettings = {
...settings,
shared: {
...settings.shared,
background: new Color(settings.shared.background ?? 'FFFFFF00'),
background: new Color(settings.shared.background!),
size: new Vector2(settings.shared.size),
},
};

return {
...project,
name: project.name ?? 'project',
settings: modifiedSettings,
settings: convertedSettings,
plugins: [],
logger: new Logger(),
versions: createVersionObject('0.5.9'),
Expand Down
28 changes: 14 additions & 14 deletions packages/core/src/exporter/FFmpegExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ export class FFmpegExporterClient implements Exporter {
public static readonly id = '@revideo/core/ffmpeg';
public static readonly displayName = 'Video (FFmpeg)';

public static async create(project: Project, settings: RendererSettings) {
return new FFmpegExporterClient(project, settings);
private readonly settings: RendererSettings;
private readonly exporterOptions: FfmpegExporterOptions;

public static async create(_: Project, settings: RendererSettings) {
return new FFmpegExporterClient(settings);
}

private static readonly response = new EventDispatcher<ServerResponse>();
Expand All @@ -61,23 +64,21 @@ export class FFmpegExporterClient implements Exporter {
}
}

public constructor(
private readonly project: Project,
private readonly settings: RendererSettings,
) {}
public constructor(settings: RendererSettings) {
if (settings.exporter.name !== FFmpegExporterClient.id) {
throw new Error('Invalid exporter');
}
this.settings = settings;
this.exporterOptions = settings.exporter.options;
}

public async start(): Promise<void> {
await this.invoke('start', this.settings);
}

public async handleFrame(canvas: HTMLCanvasElement): Promise<void> {
const format = (this.settings.exporter.options as FfmpegExporterOptions)
.format;
const blob = await new Promise<Blob | null>(resolve =>
canvas.toBlob(
resolve,
['proRes', 'webm'].includes(format) ? 'image/png' : 'image/jpeg',
),
canvas.toBlob(resolve, 'image/png'),
);

if (!blob) {
Expand Down Expand Up @@ -139,8 +140,7 @@ export class FFmpegExporterClient implements Exporter {
public async mergeMedia(): Promise<void> {
const outputFilename = this.settings.name;
const tempDir = `revideo-${this.settings.name}-${this.settings.hiddenFolderId}`;
const format = (this.settings.exporter.options as FfmpegExporterOptions)
.format;
const format = this.exporterOptions.format;

await fetch('/audio-processing/merge-media', {
method: 'POST',
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/exporter/WasmExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import type {AssetInfo, RendererSettings} from '../app/Renderer';
import {Exporter} from './Exporter';
import {download} from './download-videos';

export interface WasmExporterOptions {
format: 'mp4';
}

export class WasmExporter implements Exporter {
public static readonly id = '@revideo/core/wasm';
public static readonly displayName = 'Video (Wasm)';
Expand Down Expand Up @@ -76,6 +72,7 @@ export class WasmExporter implements Exporter {
): Promise<void> {
await fetch('/audio-processing/generate-audio', {
method: 'POST',
// TODO: add type and validate on the other side
body: JSON.stringify({
tempDir: `revideo-${this.settings.name}-${this.settings.hiddenFolderId}`,
assets,
Expand All @@ -89,15 +86,14 @@ export class WasmExporter implements Exporter {
public async mergeMedia(): Promise<void> {
const outputFilename = this.settings.name;
const tempDir = `revideo-${this.settings.name}-${this.settings.hiddenFolderId}`;
const format = (this.settings.exporter.options as WasmExporterOptions)
.format;

await fetch('/audio-processing/merge-media', {
method: 'POST',
// TODO: add type and validate on the other side
body: JSON.stringify({
outputFilename,
tempDir,
format,
format: 'mp4',
}),
});
}
Expand Down
15 changes: 10 additions & 5 deletions packages/ffmpeg/src/ffmpeg-exporter-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {
FfmpegExporterOptions,
RendererResult,
RendererSettings,
import {
FFmpegExporterClient,
type FfmpegExporterOptions,
type RendererResult,
type RendererSettings,
} from '@revideo/core';
import {EventName, sendEvent} from '@revideo/telemetry';
import * as ffmpeg from 'fluent-ffmpeg';
Expand Down Expand Up @@ -40,8 +41,12 @@ export class FFmpegExporterServer {
private readonly format: FfmpegExporterOptions['format'];

public constructor(settings: FFmpegExporterSettings) {
if (settings.exporter.name !== FFmpegExporterClient.id) {
throw new Error('Invalid exporter');
}

this.settings = settings;
this.format = (settings.exporter.options as FfmpegExporterOptions).format;
this.format = settings.exporter.options.format;

this.jobFolder = path.join(
os.tmpdir(),
Expand Down
2 changes: 0 additions & 2 deletions packages/renderer/client/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ declare global {

/**
* Render the project.
* @param project - The project to render.
* @param range - The range of frames to render.
*/
export const render = async (
project: Project,
Expand Down
Loading

0 comments on commit 73e8574

Please sign in to comment.