@remotion/media 的内存缓存
[@remotion/media](/docs/media) 会保存最近解码的视频和音频帧的缓存。
机制
🌐 Mechanism
视频流由关键帧和差分帧组成。
为了对差分帧进行解码,还需要解码最后的关键帧以及自上一个关键帧以来的所有差分帧。
🌐 Video streams consist of key frames and delta frames.
In order to decode a delta frame, the last keyframe and all the delta frames since the last keyframe also need to be decoded.
由于 Remotion 的多线程渲染和每帧独立,视频帧按其自然顺序的需求无法得到保证。
🌐 Due to Remotion's multithreaded rendering and each frame being independent, it is not guaranteed that video frames are needed in their natural order.
缓存在所有 <Video> 和 <Audio> 实例之间共享。
因此,缓存的设置是按渲染而不是按标签。
🌐 The cache is shared across all of the instances of <Video> and <Audio>.
Therefore, the settings for the cache are per-render, not per tag.
默认缓存大小
🌐 Default cache size
默认情况下,缓存可能会增长到可用系统内存的50%。 强制执行最小500MB和最大20GB的限制。
🌐 By default, the cache may grow to up to 50% of the available system memory.
A minimum of 500MB and a maximum of 20GB is enforced.
自定义缓存大小
🌐 Customizing the cache size
渲染 API 允许你在每次渲染时自定义这个限制:
🌐 The rendering APIs allow you to customize this limit on a per-render basis:
renderMedia()→mediaCacheSizeInBytesrenderStill()→mediaCacheSizeInBytesselectComposition()→mediaCacheSizeInBytesrenderMediaOnCloudRun()→mediaCacheSizeInBytesrenderStillOnCloudRun()→mediaCacheSizeInBytesgetCompositionsOnLambda()→mediaCacheSizeInBytesrenderMediaOnLambda()→mediaCacheSizeInBytesrenderStillOnLambda()→mediaCacheSizeInBytesgetCompositions()→mediaCacheSizeInBytesrenderFrames()→mediaCacheSizeInBytesnpx remotion benchmark→--media-cache-size-in-bytesnpx remotion compositions→--media-cache-size-in-bytesnpx remotion render→--media-cache-size-in-bytesnpx remotion still→--media-cache-size-in-bytesnpx remotion lambda render→--media-cache-size-in-bytesnpx remotion lambda still→--media-cache-size-in-bytesnpx remotion lambda compositions→--media-cache-size-in-bytesnpx remotion cloudrun render→--media-cache-size-in-bytesnpx remotion cloudrun still→--media-cache-size-in-bytesnpx remotion cloudrun render→--media-cache-size-in-bytes- Remotion Studio:在“高级”选项卡下设置缓存大小