🎥 Make videos programmatically with React
`@remotion/renderer`: Safer defaults for multithreading + fix memory calculation
Jonny Burgere45e4e0d1eef
diff --git a/packages/compositor-darwin-arm64/remotion b/packages/compositor-darwin-arm64/remotionindex 8657586490..5c92729568 100755Binary files a/packages/compositor-darwin-arm64/remotion and b/packages/compositor-darwin-arm64/remotion differdiff --git a/packages/compositor-darwin-x64/remotion b/packages/compositor-darwin-x64/remotionindex aced8244fa..5696eec512 100755Binary files a/packages/compositor-darwin-x64/remotion and b/packages/compositor-darwin-x64/remotion differdiff --git a/packages/compositor-linux-arm64-gnu/remotion b/packages/compositor-linux-arm64-gnu/remotionindex 4626a1679a..45d98e4160 100755Binary files a/packages/compositor-linux-arm64-gnu/remotion and b/packages/compositor-linux-arm64-gnu/remotion differdiff --git a/packages/compositor-linux-x64-gnu/remotion b/packages/compositor-linux-x64-gnu/remotionindex 5031c6fc9a..e32de53d8d 100755Binary files a/packages/compositor-linux-x64-gnu/remotion and b/packages/compositor-linux-x64-gnu/remotion differdiff --git a/packages/compositor-linux-x64-musl/remotion b/packages/compositor-linux-x64-musl/remotionindex c1122972fd..f3d946d1c5 100755Binary files a/packages/compositor-linux-x64-musl/remotion and b/packages/compositor-linux-x64-musl/remotion differdiff --git a/packages/compositor-win32-x64-msvc/remotion.exe b/packages/compositor-win32-x64-msvc/remotion.exeindex 721e71891a..4afd2d1d1e 100755Binary files a/packages/compositor-win32-x64-msvc/remotion.exe and b/packages/compositor-win32-x64-msvc/remotion.exe differdiff --git a/packages/compositor/rust/frame_cache_manager.rs b/packages/compositor/rust/frame_cache_manager.rsindex 902bfeb8d0..a8357a5853 100644--- a/packages/compositor/rust/frame_cache_manager.rs+++ b/packages/compositor/rust/frame_cache_manager.rs@@ -90,7 +90,7 @@ impl FrameCacheManager {pub fn prune_on_thread(&mut self, max_cache_size: u64) -> Result<(), ErrorWithBacktrace> {let of_thread = self.get_to_prune_local(max_cache_size)?;- self.execute_prune(of_thread, self.thread_index)?;+ self.execute_prune(of_thread, self.thread_index, max_cache_size)?;Ok(())}@@ -322,20 +322,33 @@ impl FrameCacheManager {&mut self,to_prune: Vec<FrameCacheReference>,thread_index: usize,+ max_cache_size: u64,) -> Result<(), ErrorWithBacktrace> {let mut pruned = 0;for removal in to_prune {self.remove_item_by_id(removal)?;pruned += 1;}++ let max_cache = max_cache_size::get_instance().lock().unwrap();if pruned > 0 {_print_verbose(&format!(- "Pruned {} on thread {} to save memory, keeping {}. Cache size on thread: {}MB, total cache: {}MB",+ "Pruned {} on thread {} to save memory, keeping {}. Cache size on thread: {}MB, total cache: {}MB, max cache on thread: {}MB",pruned,thread_index,self.get_frames_in_cache()?,self.get_total_size()? / 1024 / 1024,- max_cache_size::get_instance().lock().unwrap().get_current_cache_size() / 1024 / 1024+ max_cache.get_current_cache_size() / 1024 / 1024,+ max_cache_size / 1024 / 1024+ ))?;+ } else {+ _print_verbose(&format!(+ "Nothing to prune on thread {}, frames in cache: {}, cache on thread: {}MB, total cache size: {}MB, max cache on thread: {}MB",+ thread_index,+ self.get_frames_in_cache()?,+ self.get_total_size()? / 1024 / 1024,+ max_cache.get_current_cache_size() / 1024 / 1024,+ max_cache_size / 1024 / 1024))?;}Ok(())diff --git a/packages/compositor/rust/long_running_process.rs b/packages/compositor/rust/long_running_process.rsindex 890b34c686..2fe0bf927e 100644--- a/packages/compositor/rust/long_running_process.rs+++ b/packages/compositor/rust/long_running_process.rs@@ -25,6 +25,7 @@ pub struct LongRunningProcess {receive_video_stats_in_main_thread_handles: Vec<mpsc::Receiver<OpenVideoStats>>,receive_close_video_in_main_thread_handles: Vec<mpsc::Receiver<()>>,finish_thread_handles: Mutex<Vec<JoinHandle<()>>>,+ max_thread: usize,}impl LongRunningProcess {@@ -42,6 +43,7 @@ impl LongRunningProcess {receive_video_stats_in_main_thread_handles,receive_close_video_in_main_thread_handles,finish_thread_handles,+ max_thread: threads,};map}@@ -142,7 +144,7 @@ impl LongRunningProcess {let input_to_send = parse_cli(&input)?;self.send_to_thread_handles[thread_to_use.thread_id].send(CliInputAndMaxCacheSize {cli_input: input_to_send,- max_cache_size: self.maximum_frame_cache_size_in_bytes,+ max_cache_size: self.maximum_frame_cache_size_in_bytes / self.max_thread as u64,})?;Ok(())}@@ -214,7 +216,7 @@ impl LongRunningProcess {}),nonce: "".to_string(),},- max_cache_size: self.maximum_frame_cache_size_in_bytes,+ max_cache_size: maximum_frame_cache_size_in_bytes / threads as u64,})?;}diff --git a/packages/compositor/rust/opened_stream.rs b/packages/compositor/rust/opened_stream.rsindex a4695d3180..30fe96d3c5 100644--- a/packages/compositor/rust/opened_stream.rs+++ b/packages/compositor/rust/opened_stream.rs@@ -6,7 +6,7 @@ extern crate ffmpeg_next as remotionffmpeg;use std::time::UNIX_EPOCH;use crate::{- errors::ErrorWithBacktrace, frame_cache::{get_frame_cache_id, FrameCacheItem}, frame_cache_manager::FrameCacheManager, global_printer::_print_verbose, rotation, scalable_frame::{NotRgbFrame, Rotate, ScalableFrame}, tone_map::FilterGraph+ errors::ErrorWithBacktrace, frame_cache::{get_frame_cache_id, FrameCacheItem}, frame_cache_manager::FrameCacheManager, global_printer::_print_verbose, rotation, scalable_frame::{NotRgbFrame, Rotate, ScalableFrame}, tone_map::FilterGraph};pub struct OpenedStream {@@ -165,7 +165,7 @@ impl OpenedStream {tone_mapped: bool,frame_cache_manager: &mut FrameCacheManager,thread_index: usize,- max_cache_size: u64+ max_cache_size_in_bytes: u64) -> Result<usize, ErrorWithBacktrace> {let mut freshly_seeked = false;let position_to_seek_to = match self.duration_or_zero {@@ -369,7 +369,7 @@ impl OpenedStream {self.last_position = Some(unfiltered.pts().expect("expected pts"));freshly_seeked = false;- frame_cache_manager+ frame_cache_manager.add_to_cache(&self.src,&self.original_src,@@ -382,8 +382,8 @@ impl OpenedStream {items_in_loop += 1;- if items_in_loop % 10 == 0 {- frame_cache_manager.prune_on_thread(max_cache_size)?;+ if items_in_loop % 5 == 0 {+ frame_cache_manager.prune_on_thread(max_cache_size_in_bytes)?;}match stop_after_n_diverging_pts {diff --git a/packages/renderer/src/options/offthreadvideo-threads.tsx b/packages/renderer/src/options/offthreadvideo-threads.tsxindex f3832441c2..d8663e2d77 100644--- a/packages/renderer/src/options/offthreadvideo-threads.tsx+++ b/packages/renderer/src/options/offthreadvideo-threads.tsx@@ -50,4 +50,4 @@ export const offthreadVideoThreadsOption = {},} satisfies AnyRemotionOption<number | null>;-export const DEFAULT_RENDER_FRAMES_OFFTHREAD_VIDEO_THREADS = 3;+export const DEFAULT_RENDER_FRAMES_OFFTHREAD_VIDEO_THREADS = 2;