use std::path::{Path, PathBuf};
use clap::Subcommand;
use gamut::av1::encode_still_lossless_identity;
use gamut::color::Planar8;
use crate::error::CliError;
use crate::input::decode_rgb8;
#[derive(Subcommand)]
pub(crate) enum Av1Command {
Encode {
input: PathBuf,
output: PathBuf,
},
}
pub(crate) fn run(cmd: &Av1Command) -> Result<(), CliError> {
match cmd {
Av1Command::Encode { input, output } => encode(input, output),
}
}
fn encode(input: &Path, output: &Path) -> Result<(), CliError> {
let (rgb, dims) = decode_rgb8(input)?;
let planes = Planar8::from_rgb8_identity(&rgb, dims.width, dims.height)?;
let still = encode_still_lossless_identity(&planes)?;
tracing::info!(
seq_profile = still.config.seq_profile,
seq_level_idx_0 = still.config.seq_level_idx_0,
bytes = still.obus.len(),
"encoded AV1 temporal unit"
);
std::fs::write(output, &still.obus).map_err(|source| CliError::Io {
path: output.to_path_buf(),
source,
})?;
println!(
"wrote {} ({}x{}, {} bytes, lossless AV1 OBU)",
output.display(),
dims.width,
dims.height,
still.obus.len(),
);
Ok(())
}