Skip to main content

getCompositions()

@remotion/renderer 包的一部分。

根据 Remotion Bundle 评估 Remotion Root,获取在 Remotion 项目中定义的合成列表。

对于每个合成,将评估它们的 calculateMetadata() 函数。如果您只想评估要渲染的一个合成,请使用 selectComposition()

ts
const getCompositions: (
serveUrlOrWebpackUrl: string,
options?: GetCompositionsConfig,
) => Promise<TComposition[]>;
ts
const getCompositions: (
serveUrlOrWebpackUrl: string,
options?: GetCompositionsConfig,
) => Promise<TComposition[]>;

参数

serveUrlOrWebpackUrl

指向由 bundle() 生成的 Remotion Bundle 或托管捆绑的 Remotion 项目的 URL 的字符串。

options?

可选的

包含以下一个或多个选项的对象:

inputProps

在 <5.0 中是可选的,在 5.0 中是必需的

要传递给视频所选合成的输入属性。
必须是一个 JSON 对象。
从根组件中,可以使用 getInputProps() 读取属性。
您可以使用 calculateMetadata() 转换输入属性。

puppeteerInstance?v3.0.0

可选的

已打开的 Puppeteer Browser 实例。使用 openBrowser() 创建一个新实例。在多个函数调用之间重用浏览器可以加快渲染过程。您负责自行打开和关闭浏览器。如果不指定此选项,将在最后打开并关闭一个新浏览器。

browserExecutable?v2.3.1

定义应使用的浏览器可执行文件的磁盘上的绝对路径的字符串。默认情况下,Remotion 将尝试自动检测并下载一个,如果没有可用的,则会下载一个。如果定义了 puppeteerInstance,它将优先于 browserExecutable

onBrowserLog?v3.0.0

可选

当您的项目调用 console.log 或控制台的另一个方法时调用。浏览器日志有三个属性:

  • text: 被打印的消息
  • stackTrace: 包含以下属性的对象数组:
    • url: 记录日志的资源的 URL。
    • lineNumber: 文件中调用日志的基于 0 的行号。
    • columnNumber: 文件中调用日志的基于 0 的列号。
  • type: 控制台方法之一 - log, debug, info, error, warning, dir, dirxml, table, trace, clear, startGroup, startGroupCollapsed, endGroup, assert, profile, profileEnd, count, timeEnd, verbose 中的一个
tsx
getCompositions({
// ...
onBrowserLog: (info) => {
console.log(`${info.type}: ${info.text}`);
console.log(
info.stackTrace
.map((stack) => {
return ` ${stack.url}:${stack.lineNumber}:${stack.columnNumber}`;
})
.join('\n'),
);
},
});
tsx
getCompositions({
// ...
onBrowserLog: (info) => {
console.log(`${info.type}: ${info.text}`);
console.log(
info.stackTrace
.map((stack) => {
return ` ${stack.url}:${stack.lineNumber}:${stack.columnNumber}`;
})
.join('\n'),
);
},
});

timeoutInMilliseconds?v2.6.3

描述一个帧可能需要多长时间来解析所有 delayRender() 调用,否则渲染超时并失败。默认值:30000

port?

优先使用特定端口来提供 Remotion 项目。如果未指定,将使用随机端口。

logLevel?v4.0.0

One of verbose, info, warn, error.
Determines how much is being logged to the console.
verbose will also log console.log's from the browser.
Default info.

chromiumOptions?v2.6.5

可选

允许您设置某些 Chromium / Google Chrome 标志。参见:Chromium 标志

offthreadVideoCacheSizeInBytes?v4.0.23

From v4.0, Remotion has a cache for <OffthreadVideo> frames. The default is null, corresponding to half of the system memory available when the render starts.
This option allows to override the size of the cache. The higher it is, the faster the render will be, but the more memory will be used.
The used value will be printed when running in verbose mode.
Default: null

binariesDirectory?v4.0.120

The directory where the platform-specific binaries and libraries that Remotion needs are located. Those include an ffmpeg and ffprobe binary, a Rust binary for various tasks, and various shared libraries. If the value is set to null, which is the default, then the path of a platform-specific package located at node_modules/@remotion/compositor-* is selected.
This option is useful in environments where Remotion is not officially supported to run like bundled serverless functions or Electron.

onBrowserDownload?v4.0.137

Gets called when no compatible local browser is detected on the system and this API needs to download a browser. Return a callback to observe progress. See here for how to use this option.

ffmpegExecutable

在 v4.0 中已移除,可选

覆盖要使用的 ffmpeg 可执行文件的绝对路径。

ffprobeExecutable? v3.0.17

在 v4.0 中已移除

覆盖要使用的 ffprobe 可执行文件的绝对路径。

返回值

返回一个解析为可用合成数组的 Promise。示例值:

ts
[
{
id: 'HelloWorld',
width: 1920,
height: 1080,
fps: 30,
durationInFrames: 120,
defaultProps: {
title: 'Hello World',
},
},
{
id: 'Title',
width: 1080,
height: 1080,
fps: 30,
durationInFrames: 90,
defaultProps: undefined,
},
];
ts
[
{
id: 'HelloWorld',
width: 1920,
height: 1080,
fps: 30,
durationInFrames: 120,
defaultProps: {
title: 'Hello World',
},
},
{
id: 'Title',
width: 1080,
height: 1080,
fps: 30,
durationInFrames: 90,
defaultProps: undefined,
},
];

defaultProps 仅在 v2.5.7 版本之后返回。

参见