Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
aa96ab0
feat: parallel rendering, make ffmpeg exporter default
justusmattern27 Apr 26, 2024
cad994c
chore: cleanup
justusmattern27 Apr 28, 2024
fff0cec
style: run prettier
justusmattern27 Apr 28, 2024
de0ae66
style: run prettier
justusmattern27 Apr 28, 2024
a9b532e
chore: fix imports
justusmattern27 Apr 28, 2024
6c30ede
chore: dependencies
justusmattern27 Apr 28, 2024
40b070d
chore: dependencies
justusmattern27 Apr 28, 2024
599c313
chore: fix tsconfig
justusmattern27 Apr 28, 2024
0b51216
fix: assign hidden folder id to prevent conflicts
justusmattern27 Apr 28, 2024
ce6db7d
chore: fix package-lock, remove logs
justusmattern27 Apr 28, 2024
156f85c
chore: pin dependencies
justusmattern27 Apr 28, 2024
9dec9f8
chore: package lock
justusmattern27 Apr 28, 2024
d218ed1
chore: rebuild
justusmattern27 Apr 28, 2024
f58e2b2
chore: fix dependencies
justusmattern27 Apr 28, 2024
017e822
chore: add ffmpeg to tests
justusmattern27 Apr 28, 2024
80efb81
chore: package-lock
justusmattern27 Apr 28, 2024
50c2085
ci: add ffmpeg to test action
justusmattern27 Apr 28, 2024
1faa30c
ci: add ffmpeg to e2e tests
justusmattern27 Apr 28, 2024
5234827
ci: add ffmpeg to all actions
justusmattern27 Apr 28, 2024
a55f155
style: remove unnecessary linebreaks
justusmattern27 Apr 29, 2024
b4d0707
perf: dont await all server starts before rendering
justusmattern27 Apr 29, 2024
e9e89ef
perf: faster file cleanup
justusmattern27 Apr 29, 2024
aae8f1e
chore: change back preview fps
justusmattern27 Apr 29, 2024
8d49560
chore: rename numworkers to workers
justusmattern27 Apr 29, 2024
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
Prev Previous commit
Next Next commit
fix: assign hidden folder id to prevent conflicts
  • Loading branch information
justusmattern27 committed Apr 28, 2024
commit 0b512165f8e9169a9cc4b8d5ccf5ed52d9144485
1 change: 1 addition & 0 deletions packages/core/src/app/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RendererSettings extends StageSettings {
name: string;
options: unknown;
};
hiddenFolderId?: string;
}

export interface AssetInfo {
Expand Down
6 changes: 5 additions & 1 deletion packages/ffmpeg/src/FFmpegExporterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export class FFmpegExporterServer {

public constructor(settings: FFmpegExporterSettings) {
this.settings = settings;
this.jobFolder = path.join(os.tmpdir(), `revideo-${this.settings.name}`);
this.jobFolder = path.join(
`${os.tmpdir()}`,
`revideo-${this.settings.name}-${settings.hiddenFolderId}`,
);
console.log('jobFolder', this.jobFolder);
this.audioFilenames = [];
this.stream = new ImageStream();
this.command = ffmpeg();
Expand Down
6 changes: 2 additions & 4 deletions packages/ffmpeg/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ export async function createSilentAudioFile(
) {
return new Promise((resolve, reject) => {
ffmpeg()
.addInput('anullsrc')
.addInput(`anullsrc=channel_layout=stereo:sample_rate=${48000}`)
.inputFormat('lavfi')
.audioChannels(2)
.audioFrequency(48000)
.outputOptions(['-t', duration.toString(), '-acodec', 'aac'])
.duration(duration)
.on('end', () => {
resolve(filePath);
})
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/client/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const render = async (
totalNumOfWorkers: number,
startInSeconds: number,
endInSeconds: number,
hiddenFolderId: string,
) => {
try {
const renderer = new Renderer(project);
Expand All @@ -41,6 +42,7 @@ export const render = async (
await renderer.render({
...project.meta.getFullRenderingSettings(),
name: project.name,
hiddenFolderId: hiddenFolderId,
range: [
renderer.frameToTime(firstWorkerFrame),
renderer.frameToTime(lastWorkerFrame),
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer/server/RendererPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ export function rendererPlugin(params?: Record<string, unknown>): Plugin {
const totalNumOfWorkers = url.searchParams.get('totalNumOfWorkers');
const startInSeconds = parseFloat(url.searchParams.get('startInSeconds'));
const endInSeconds = parseFloat(url.searchParams.get('endInSeconds'));
const hiddenFolderId = url.searchParams.get('hiddenFolderId');

// Overwrite project name so that the rendered videos don't overwrite each other
project.name = fileName;

render(project, workerId, totalNumOfWorkers, startInSeconds, endInSeconds);
render(project, workerId, totalNumOfWorkers, startInSeconds, endInSeconds, hiddenFolderId);
`;
}
},
Expand Down
22 changes: 16 additions & 6 deletions packages/renderer/server/renderVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as os from 'os';
import * as path from 'path';
import puppeteer, {Browser, BrowserLaunchArgumentOptions} from 'puppeteer';
import * as readline from 'readline';
import {v4 as uuidv4} from 'uuid';
import {ViteDevServer, createServer} from 'vite';
import {rendererPlugin} from './RendererPlugin';

Expand All @@ -19,8 +20,9 @@ function buildUrl(
workerId: number,
totalNumOfWorkers: number,
range: [number, number] = [0, Infinity],
hiddenFolderId: string,
) {
return `http://localhost:${port}/render?fileName=${fileName}&workerId=${workerId}&totalNumOfWorkers=${totalNumOfWorkers}&startInSeconds=${range[0]}&endInSeconds=${range[1]}`;
return `http://localhost:${port}/render?fileName=${fileName}&workerId=${workerId}&totalNumOfWorkers=${totalNumOfWorkers}&startInSeconds=${range[0]}&endInSeconds=${range[1]}&hiddenFolderId=${hiddenFolderId}`;
}

interface RenderVideoSettings {
Expand All @@ -43,6 +45,7 @@ export const renderVideo = async (

const resolvedConfigPath = path.resolve(process.cwd(), configFile);
const projectName = settings.name ?? 'project';
const hiddenFolderId = uuidv4();

/**
* TODO: Change this in the future after more testing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete this todo haha

Expand Down Expand Up @@ -72,6 +75,7 @@ export const renderVideo = async (
i,
numOfWorkers,
settings.range,
hiddenFolderId,
);

renderPromises.push(renderVideoOnPage(browser, server, url));
Expand All @@ -82,8 +86,8 @@ export const renderVideo = async (
const audioFiles = [];
const videoFiles = [];
for (let i = 0; i < numOfWorkers; i++) {
const videoFilePath = `${os.tmpdir()}/revideo-${projectName}-${i}/visuals.mp4`;
const audioFilePath = `${os.tmpdir()}/revideo-${projectName}-${i}/audio.wav`;
const videoFilePath = `${os.tmpdir()}/revideo-${projectName}-${i}-${hiddenFolderId}/visuals.mp4`;
const audioFilePath = `${os.tmpdir()}/revideo-${projectName}-${i}-${hiddenFolderId}/audio.wav`;

if (!(await doesFileExist(audioFilePath))) {
const videoDuration = await getVideoDuration(videoFilePath);
Expand Down Expand Up @@ -111,7 +115,7 @@ export const renderVideo = async (
`\nRendered successfully! Video saved to: ${path.join(process.cwd(), `output/${projectName}.mp4`)}`,
);

await cleanup(projectName, numOfWorkers);
await cleanup(projectName, numOfWorkers, hiddenFolderId);
};

async function initBrowserAndServer(
Expand Down Expand Up @@ -197,11 +201,17 @@ async function renderVideoOnPage(
return renderingComplete;
}

async function cleanup(projectName: string, numOfWorkers: number) {
async function cleanup(
projectName: string,
numOfWorkers: number,
hiddenFolderId: string,
) {
const cleanupFolders = [];
const cleanupFiles = [];
for (let i = 0; i < numOfWorkers; i++) {
cleanupFolders.push(`${os.tmpdir()}/revideo-${projectName}-${i}`);
cleanupFolders.push(
`${os.tmpdir()}/revideo-${projectName}-${i}-${hiddenFolderId}`,
);
cleanupFiles.push(
path.join(process.cwd(), `output/${projectName}-${i}.mp4`),
);
Expand Down