limit the ram usage of ffmpeg

This commit is contained in:
Dominic 2023-11-02 10:23:31 +01:00
parent 164bb8faa3
commit 2a8ba70e23
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -21,6 +21,8 @@ use std::{
process::{Command, Stdio}
};
const MEMORY_LIMIT: &str = "2G";
const INTRO_LEN: Time = Time {
seconds: 3,
micros: 0
@ -39,8 +41,18 @@ const FF_LOGO_SIZE: usize = 128;
const LOGO_SIZE: usize = 96;
fn cmd() -> Command {
let mut cmd = Command::new("busybox");
cmd.arg("ash")
// we use systemd-run to limit the process memory
// I tried others like ulimit, chpst or isolate, but none worked
let mut cmd = Command::new("systemd-run");
cmd.arg("--scope")
.arg("-q")
.arg("--expand-environment=no")
.arg("-p")
.arg(format!("MemoryMax={MEMORY_LIMIT}"))
.arg("--user");
// we use busybox ash for having a shell that outputs commands with -x
cmd.arg("busybox")
.arg("ash")
.arg("-exuo")
.arg("pipefail")
.arg("-c")