🎥 Make videos programmatically with React
further simplification
Jonny Burger32f4cb157a97
diff --git a/packages/docs/docs/3-0-migration.md b/packages/docs/docs/3-0-migration.mdindex 14454f4699..d64703a84e 100644--- a/packages/docs/docs/3-0-migration.md+++ b/packages/docs/docs/3-0-migration.md@@ -31,3 +31,5 @@ This parameter did probably not to what you thought it would. To avoid any confuThe necessary information is not embedded in `assetsInfo`, embedded in the return value of `renderFrames()`. The parameter `imageFormat` is not necessary anymore to pass into `stitchFramesToVideo()`.**Upgrade path**: Remove the `imageFormat` option from `stitchFramesToVideo()`.++## Removed `webpackBundle` from `stitchFramesToVideo` APIdiff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.tsindex c05f238f66..f424c3a0ce 100644--- a/packages/lambda/src/functions/renderer.ts+++ b/packages/lambda/src/functions/renderer.ts@@ -1,9 +1,5 @@import {InvokeCommand} from '@aws-sdk/client-lambda';-import {- renderFrames,- RenderInternals,- stitchFramesToVideo,-} from '@remotion/renderer';+import {RenderInternals, renderMedia} from '@remotion/renderer';import {BrowserLog} from '@remotion/renderer';import fs from 'fs';import path from 'path';@@ -32,7 +28,6 @@ import {getCurrentRegionInFunction} from './helpers/get-current-region';import {getFolderFiles} from './helpers/get-files-in-folder';import {getFolderSizeRecursively} from './helpers/get-folder-size';import {lambdaWriteFile} from './helpers/io';-import {timer} from './helpers/timer';import {uploadBrowserLogs} from './helpers/upload-browser-logs';import {getTmpDirStateIfENoSp,@@ -59,6 +54,10 @@ const renderHandler = async ((fs.rmSync ?? fs.rmdirSync)(outputPath);}+ if (!fs.existsSync(DOWNLOADS_DIR)) {+ fs.mkdirSync(DOWNLOADS_DIR);+ }+fs.mkdirSync(outputPath);if (typeof params.chunk !== 'number') {@@ -76,7 +75,18 @@ const renderHandler = async (frameRange: params.frameRange,startDate: start,};- const {assetsInfo} = await renderFrames({++ const outdir = tmpDir(RENDERER_PATH_TOKEN);++ const outputLocation = path.join(+ outdir,+ `localchunk-${String(params.chunk).padStart(+ 8,+ '0'+ )}.${getFileExtensionFromCodec(params.codec, 'chunk')}`+ );++ await renderMedia({config: {id: params.composition,durationInFrames: params.durationInFrames,@@ -87,8 +97,8 @@ const renderHandler = async (imageFormat: params.imageFormat,inputProps: params.inputProps,frameRange: params.frameRange,- onFrameUpdate: (i: number, frameNumber: number) => {- chunkTimingData.timings[frameNumber] = Date.now() - start;+ onProgress: ({renderedFrames}) => {+ chunkTimingData.timings[renderedFrames] = Date.now() - start;},parallelism: 1,onStart: () => {@@ -113,7 +123,7 @@ const renderHandler = async (});},outputDir: outputPath,- puppeteerInstance: browserInstance,+ openedBrowser: browserInstance,serveUrl: params.serveUrl,quality: params.quality,envVariables: params.envVariables,@@ -122,45 +132,22 @@ const renderHandler = async (onBrowserLog: (log) => {logs.push(log);},- });- const outdir = tmpDir(RENDERER_PATH_TOKEN);-- const outputLocation = path.join(- outdir,- `localchunk-${String(params.chunk).padStart(- 8,- '0'- )}.${getFileExtensionFromCodec(params.codec, 'chunk')}`- );-- const stitchLabel = timer('stitcher');- if (!fs.existsSync(DOWNLOADS_DIR)) {- fs.mkdirSync(DOWNLOADS_DIR);- }-- const endRendered = Date.now();-- await stitchFramesToVideo({- assetsInfo,- downloadDir: DOWNLOADS_DIR,- dir: outputPath,- force: true,- fps: params.fps,- height: params.height,- width: params.width,- outputLocation,+ absoluteOutputFile: outputLocation,codec: params.codec,- imageFormat: params.imageFormat,- crf: params.crf,+ crf: params.crf ?? null,+ ffmpegExecutable: null,+ fileExtension: null,pixelFormat: params.pixelFormat,proResProfile: params.proResProfile,- verbose: false,- onProgress: () => {- // TODO: upload progress from time to time+ parallelEncoding: false,+ onDownload: (src: string) => {+ console.log('Downloading', src);},- webpackBundle: null,+ overwrite: false,});- stitchLabel.end();++ const endRendered = Date.now();+await RenderInternals.addSilentAudioIfNecessary(outputLocation);const condensedTimingData: ChunkTimingData = {diff --git a/packages/renderer/src/assets/convert-assets-to-file-urls.ts b/packages/renderer/src/assets/convert-assets-to-file-urls.tsindex 5363c40370..18e6cd57d6 100644--- a/packages/renderer/src/assets/convert-assets-to-file-urls.ts+++ b/packages/renderer/src/assets/convert-assets-to-file-urls.ts@@ -13,12 +13,10 @@ export const convertAssetsToFileUrls = async ({assets,downloadDir,onDownload,- webpackBundle,}: {assets: TAsset[][];downloadDir: string;onDownload: (src: string) => void;- webpackBundle: string | null;}): Promise<TAsset[][]> => {const chunks = chunk(assets, 1000);const results: TAsset[][][] = [];@@ -32,7 +30,6 @@ export const convertAssetsToFileUrls = async ({asset: a,downloadDir,onDownload,- webpackBundle,});}));diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 465db340f7..95fb888870 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -14,6 +14,8 @@ import {} from 'remotion';import {stitchFramesToVideo, spawnFfmpeg} from './stitcher';import {renderFrames} from './render';+import {BrowserLog} from './browser-log';+import {OnStartData} from './types';export type RenderMediaOnDownload = (src: string) => void;@@ -30,16 +32,17 @@ export type RenderMediaOnProgress = (progress: {export type RenderMediaOptions = {proResProfile: ProResProfile | undefined;parallelism: number | null;+ // TODO: Should rename to better signify that it's preencoding...parallelEncoding: boolean;crf: number | null;outputDir: string;config: TCompMetadata;imageFormat: 'png' | 'jpeg' | 'none';ffmpegExecutable: FfmpegExecutable;- inputProps: object;- pixelFormat: PixelFormat;+ inputProps: unknown;+ pixelFormat?: PixelFormat;codec: Codec;- envVariables: Record<string, string>;+ envVariables?: Record<string, string>;quality: number | undefined;frameRange: FrameRange | null;browser: Browser;@@ -48,12 +51,16 @@ export type RenderMediaOptions = {overwrite: boolean;absoluteOutputFile: string;onProgress?: RenderMediaOnProgress;+ // TODO: Do we really need it? Can't we derive it from codec?fileExtension: string | null;- bundled: string;onDownload: (src: string) => void;dumpBrowserLogs: boolean;+ onBrowserLog?: ((log: BrowserLog) => void) | undefined;+ onStart: (data: OnStartData) => void;+ downloadDir?: string;};+// TODO: outputDir and `absoluteOutputFile` are redundantexport const renderMedia = async ({parallelism,proResProfile,@@ -76,9 +83,11 @@ export const renderMedia = async ({onProgress,overwrite,fileExtension,- bundled,onDownload,dumpBrowserLogs,+ onBrowserLog,+ onStart,+ downloadDir,}: RenderMediaOptions) => {let stitchStage: StitchingState = 'encoding';let stitcherFfmpeg: ExecaChildProcess<string> | undefined;@@ -117,7 +126,6 @@ export const renderMedia = async ({fps: config.fps,outputLocation: preEncodedFileLocation,force: true,- imageFormat,pixelFormat,codec,proResProfile,@@ -128,7 +136,6 @@ export const renderMedia = async ({},verbose: Internals.Logging.isEqualOrBelowLogLevel('verbose'),parallelEncoding,- webpackBundle: bundled,ffmpegExecutable,assetsInfo: {assets: [], imageSequenceName: ''},});@@ -143,9 +150,10 @@ export const renderMedia = async ({},parallelism,outputDir,- onStart: () => {+ onStart: (data) => {renderedFrames = 0;callUpdate();+ onStart(data);},inputProps,envVariables,@@ -159,6 +167,7 @@ export const renderMedia = async ({},serveUrl,dumpBrowserLogs,+ onBrowserLog,});if (stitcherFfmpeg) {stitcherFfmpeg?.stdin?.end();@@ -191,7 +200,6 @@ export const renderMedia = async ({outputLocation: absoluteOutputFile,preEncodedFileLocation,force: overwrite,- imageFormat,pixelFormat,codec,proResProfile,@@ -205,11 +213,13 @@ export const renderMedia = async ({},// TODO: Optimization, Now can download before!onDownload,- webpackBundle: bundled,verbose: Internals.Logging.isEqualOrBelowLogLevel('verbose'),+ parallelEncoding: false,+ downloadDir,});encodedFrames = config.durationInFrames;encodedDoneIn = Date.now() - stitchStart;callUpdate();+ // TODO: Cleanupawait closeBrowserPromise;};diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.tsindex eb8619f626..33585f1270 100644--- a/packages/renderer/src/stitcher.ts+++ b/packages/renderer/src/stitcher.ts@@ -47,7 +47,6 @@ export type StitcherOptions = {verbose?: boolean;parallelEncoding?: boolean;preEncodedFileLocation?: string;- webpackBundle: string | null;downloadDir?: string;ffmpegExecutable?: FfmpegExecutable;};@@ -66,7 +65,6 @@ const getAssetsData = async (options: StitcherOptions) => {convertAssetsToFileUrls({assets: options.assetsInfo.assets,downloadDir: options.downloadDir ?? (await makeAssetsDownloadTmpDir()),- webpackBundle: options.webpackBundle,onDownload: options.onDownload ?? (() => undefined),}),]);