use clap::Parser;
use tracing_subscriber::EnvFilter;
mod cli;
mod file_mode;
mod ingest;
mod progress;
mod stream_mode;
use cli::{Args, Command, InputSource};
use ingest::CliOptions;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
const DEFAULT_WORKERS: usize = 2;
fn run_input(opts: &CliOptions, input: &InputSource, workers: Option<usize>) -> Result<(), anyhow::Error> {
match input {
InputSource::File(path) => file_mode::run_file(opts, path, workers.unwrap_or(DEFAULT_WORKERS)),
stream @ (InputSource::Stdin | InputSource::Fd(_)) => {
if workers.is_some() {
tracing::warn!("--workers is ignored for piped input, which cannot be split by scene");
}
tracing::info!(input = %stream, "reading a y4m stream");
stream_mode::run_stream(opts, stream.open_reader()?)
},
}
}
fn main() -> anyhow::Result<()> {
if std::env::var_os("RUST_MIN_STACK").is_none() {
unsafe { std::env::set_var("RUST_MIN_STACK", "16777216") };
}
let args = Args::parse();
if std::env::var("RUST_LOG").is_err() {
unsafe { std::env::set_var("RUST_LOG", "info") };
}
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(progress::tracing_writer())
.init();
match av_denoise::apply_compilation_cache_env() {
Ok(Some(path)) => {
tracing::info!(?path, "AV_DENOISE_COMPILATION_CACHE override active")
},
Ok(None) => {},
Err(_) => anyhow::bail!("unable to apply AV_DENOISE_COMPILATION_CACHE, this is a bug."),
}
let Command::Nlmeans(nlm) = &args.command;
let opts = nlm.build_options(&args)?;
run_input(&opts, &nlm.input, nlm.workers)
}