allow compiling out systemd-run support
This commit is contained in:
parent
0d98ab21f0
commit
4612cbdfaa
4 changed files with 37 additions and 18 deletions
|
@ -17,3 +17,7 @@ serde = { version = "1.0.188", features = ["derive"] }
|
|||
serde_with = "3.4"
|
||||
svgwriter = "0.1"
|
||||
toml = { package = "basic-toml", version = "0.1.4" }
|
||||
|
||||
[features]
|
||||
default = ["mem_limit"]
|
||||
mem_limit = []
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -16,15 +16,17 @@ use iotro::Language;
|
|||
use rational::Rational;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{serde_as, DisplayFromStr};
|
||||
#[cfg(feature = "mem_limit")]
|
||||
use std::sync::RwLock;
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
fmt::Display,
|
||||
fs,
|
||||
io::{self, BufRead as _, Write},
|
||||
str::FromStr,
|
||||
sync::RwLock
|
||||
str::FromStr
|
||||
};
|
||||
|
||||
#[cfg(feature = "mem_limit")]
|
||||
static MEM_LIMIT: RwLock<String> = RwLock::new(String::new());
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
@ -49,6 +51,7 @@ struct Args {
|
|||
#[clap(short = 'L', long, default_value = "de")]
|
||||
lang: Language<'static>,
|
||||
|
||||
#[cfg(feature = "mem_limit")]
|
||||
/// The memory limit for external tools like ffmpeg.
|
||||
#[clap(short, long, default_value = "12G")]
|
||||
mem_limit: String,
|
||||
|
@ -231,7 +234,11 @@ fn ask_time(question: impl Display) -> Time {
|
|||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
#[cfg(feature = "mem_limit")]
|
||||
{
|
||||
*(MEM_LIMIT.write().unwrap()) = args.mem_limit;
|
||||
}
|
||||
|
||||
// process arguments
|
||||
let directory = args.directory.canonicalize_utf8().unwrap();
|
||||
|
|
|
@ -105,8 +105,10 @@ impl FfmpegOutput {
|
|||
const QUALITY: &str = "22";
|
||||
if venc {
|
||||
let vcodec = match (self.format, vaapi) {
|
||||
(FfmpegOutputFormat::Av1Flac, false) | (FfmpegOutputFormat::Av1Opus, false) => "libsvtav1",
|
||||
(FfmpegOutputFormat::Av1Flac, true) | (FfmpegOutputFormat::Av1Opus, true) => "av1_vaapi",
|
||||
(FfmpegOutputFormat::Av1Flac, false)
|
||||
| (FfmpegOutputFormat::Av1Opus, false) => "libsvtav1",
|
||||
(FfmpegOutputFormat::Av1Flac, true)
|
||||
| (FfmpegOutputFormat::Av1Opus, true) => "av1_vaapi",
|
||||
(FfmpegOutputFormat::AvcAac, false) => "h264",
|
||||
(FfmpegOutputFormat::AvcAac, true) => "h264_vaapi"
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
iotro::{intro, outro},
|
||||
render::ffmpeg::{Ffmpeg, FfmpegInput},
|
||||
time::{format_date, Time},
|
||||
Project, ProjectSourceMetadata, Resolution, MEM_LIMIT
|
||||
Project, ProjectSourceMetadata, Resolution
|
||||
};
|
||||
use anyhow::{bail, Context};
|
||||
use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
|
||||
|
@ -39,6 +39,8 @@ const FF_LOGO_SIZE: usize = 128;
|
|||
const LOGO_SIZE: usize = 96;
|
||||
|
||||
fn cmd() -> Command {
|
||||
#[cfg(feature = "mem_limit")]
|
||||
let mut cmd = {
|
||||
// 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");
|
||||
|
@ -46,11 +48,15 @@ fn cmd() -> Command {
|
|||
.arg("-q")
|
||||
.arg("--expand-environment=no")
|
||||
.arg("-p")
|
||||
.arg(format!("MemoryMax={}", MEM_LIMIT.read().unwrap()))
|
||||
.arg(format!("MemoryMax={}", crate::MEM_LIMIT.read().unwrap()))
|
||||
.arg("--user");
|
||||
// we use busybox ash for having a shell that outputs commands with -x
|
||||
cmd.arg("busybox")
|
||||
.arg("ash")
|
||||
cmd.arg("busybox");
|
||||
cmd
|
||||
};
|
||||
#[cfg(not(feature = "mem_limit"))]
|
||||
let mut cmd = Command::new("busybox");
|
||||
cmd.arg("ash")
|
||||
.arg("-exuo")
|
||||
.arg("pipefail")
|
||||
.arg("-c")
|
||||
|
|
Loading…
Reference in a new issue