Skip to main content

自动计算作品的时长

目前不支持根据内容推导作品的持续时间。其原因如下:

🌐 It is currently not supported to derive the duration of a composition be from the content. The reason for it are the following:

  • 并非所有组合都是有限的: 这里有一个组件的例子,其持续时间是无法计算的:

    InfiniteComposition.tsx
    import React from 'react'; import {useCurrentFrame} from 'remotion'; const InfiniteComposition: React.FC = () => { const frame = useCurrentFrame(); return <div>{frame}</div>; };
  • <Series><Sequence> 也可以是动态的 虽然确实许多作品使用 <Sequence><Series>,从中在很多情况下可以推导出持续时间,但这也不是一个万无一失的解决方案。

    随着时间的推移,更改 <Sequence>fromdurationInFrames 属性的值是完全可以接受的:

    ChangingDuration.tsx
    import {Sequence, useCurrentFrame} from 'remotion'; const ChangingDuration: React.FC = () => { const frame = useCurrentFrame(); return ( // This is fine! <Sequence from={frame} durationInFrames={30}> <div>Hello World!</div> </Sequence> ); };

    一个实际的用例是随时间改变视频的播放速度

  • Remotion 只知道当前帧: Remotion 并不会像我们作为开发者那样静态地看到组件,相反,它只会在某个时间点渲染组件。为了可靠地确定组件何时停止渲染标记,Remotion 必须循环遍历所有帧,直到标记停止,这可能是一个昂贵的操作。

总之,React 的动态性不允许通过简单的方法可靠地推导出持续时间。我们预见到,如果使用启发式方法来确定持续时间而它判断错误,将导致难以调试的情况。

🌐 In summary, the dynamicity of React does not allow for a simple solution of deriving the duration reliably. We foresee that if a heuristic is used to determine the duration and it gets it wrong, it will lead to hard to debug cases.

我们建议使用此处描述的动态期限方法来计算期限。

🌐 We suggest to calculate the duration using the dynamic duration method described here.