Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Free up memory before executing a command

Jonny Burger2edcc2796f7e
diff --git a/packages/docs/docs/troubleshooting/sigkill.mdx b/packages/docs/docs/troubleshooting/sigkill.mdx
new file mode 100644
index 0000000000..d163151277
--- /dev/null
+++ b/packages/docs/docs/troubleshooting/sigkill.mdx
@@ -0,0 +1,46 @@
+---
+image: /generated/articles-docs-troubleshooting-sigkill.png
+sidebar_label: SIGKILL
+title: Process quit with signal SIGKILL
+crumb: "Troubleshooting"
+---
+
+This error comes in multiple variants:
+
+```txt title="Remotion Rust process killed"
+Compositor quit with signal SIGKILL: [...]
+```
+
+```txt title="FFmpeg process killed"
+FFmpeg quit with code null (SIGKILL)
+```
+
+## What is happening?
+
+The operating system is either killing the Remotion process or the FFmpeg process.
+Most likely this is due to it taking too much memory.
+
+## Memory management in Remotion
+
+Remotion opens a cache for extracting video frames, which by default allows itself to fill up to 50% of the available memory used at the begin of the render.
+If Remotion realizes that the system is short on memory, it will halfen the cache size and free up memory.
+
+However, if other processes are filling up memory, the Remotion process can be killed as soon as it allocates any memory.
+The same goes for the FFmpeg process.
+
+## Lower the memory usage of Remotion
+
+You can decrease the cache size of Remotion using the [`offthreadVideoCacheSizeInBytes`](`/docs/renderer/select-composition#offthreadvideocachesizeinbytes`).
+
+## Ensure your Remotion version is up to date
+
+We continuously improve the memory management of Remotion.
+The last version with improvements is [`v4.0.166`](https://remotion.dev/changelog).
+
+## Lower the concurrency of Remotion
+
+Set a lower [`concurrency`](/docs/terminology/concurrency) to open less browser tabs at once and thus less memory.
+
+## Allocate more memory to your system
+
+As a last resort, you can allocate more memory to your system to alleviate the problem.
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 1f152a37f1..d1f2196cf7 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -810,6 +810,7 @@ module.exports = {
"troubleshooting/delay-render-proxy",
"troubleshooting/bundling-bundle",
"troubleshooting/browser-launch",
+ "troubleshooting/sigkill",
],
},
{
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 2f1d3872a3..79e7706ffd 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1241,7 +1241,7 @@ export const articles = [
{
id: "getrenderprogress",
title: "getRenderProgress()",
- relativePath: "docs/lambda/getrenderprogress.md",
+ relativePath: "docs/lambda/getrenderprogress.mdx",
compId: "articles-docs-lambda-getrenderprogress",
crumb: "Lambda API",
},
@@ -3333,6 +3333,13 @@ export const articles = [
compId: "articles-docs-troubleshooting-rosetta",
crumb: "Troubleshooting",
},
+ {
+ id: "troubleshooting/sigkill",
+ title: "Process quit with signal SIGKILL",
+ relativePath: "docs/troubleshooting/sigkill.mdx",
+ compId: "articles-docs-troubleshooting-sigkill",
+ crumb: "Troubleshooting",
+ },
{
id: "troubleshooting/timed-out-page-function",
title: "Timed out evaluating page function",
diff --git a/packages/docs/static/generated/articles-docs-troubleshooting-sigkill.png b/packages/docs/static/generated/articles-docs-troubleshooting-sigkill.png
new file mode 100644
index 0000000000..f83422bfa6
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-sigkill.png differ
diff --git a/packages/renderer/rust/main.rs b/packages/renderer/rust/main.rs
index 7a27b03cd3..7a5507be40 100644
--- a/packages/renderer/rust/main.rs
+++ b/packages/renderer/rust/main.rs
@@ -97,6 +97,11 @@ fn start_long_running_process(
let mut current_maximum_cache_size = maximum_frame_cache_size_in_bytes;
pool.install(move || {
+ if is_about_to_run_out_of_memory() {
+ ffmpeg::emergency_memory_free_up().unwrap();
+ current_maximum_cache_size = current_maximum_cache_size / 2;
+ }
+
match execute_command(opts.payload, Some(current_maximum_cache_size)) {
Ok(res) => global_printer::synchronized_write_buf(0, &opts.nonce, &res).unwrap(),
Err(err) => global_printer::synchronized_write_buf(
@@ -106,10 +111,6 @@ fn start_long_running_process(
)
.unwrap(),
};
- if is_about_to_run_out_of_memory() {
- ffmpeg::emergency_memory_free_up().unwrap();
- current_maximum_cache_size = current_maximum_cache_size / 2;
- }
ffmpeg::keep_only_latest_frames_and_close_videos(current_maximum_cache_size).unwrap();
});