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