#[derive(Debug, Clone)]
pub struct H264Options {
pub profile: H264Profile,
pub level: Option<u32>,
pub bframes: u32,
pub gop_size: u32,
pub refs: u32,
pub preset: Option<H264Preset>,
pub tune: Option<H264Tune>,
}
impl Default for H264Options {
fn default() -> Self {
Self {
profile: H264Profile::High,
level: None,
bframes: 2,
gop_size: 250,
refs: 3,
preset: None,
tune: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum H264Profile {
Baseline,
Main,
#[default]
High,
High10,
}
impl H264Profile {
pub(in crate::video) fn as_str(self) -> &'static str {
match self {
Self::Baseline => "baseline",
Self::Main => "main",
Self::High => "high",
Self::High10 => "high10",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum H264Preset {
Ultrafast,
Superfast,
Veryfast,
Faster,
Fast,
Medium,
Slow,
Slower,
Veryslow,
Placebo,
}
impl H264Preset {
pub(in crate::video) fn as_str(self) -> &'static str {
match self {
Self::Ultrafast => "ultrafast",
Self::Superfast => "superfast",
Self::Veryfast => "veryfast",
Self::Faster => "faster",
Self::Fast => "fast",
Self::Medium => "medium",
Self::Slow => "slow",
Self::Slower => "slower",
Self::Veryslow => "veryslow",
Self::Placebo => "placebo",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum H264Tune {
Film,
Animation,
Grain,
Stillimage,
Psnr,
Ssim,
Fastdecode,
Zerolatency,
}
impl H264Tune {
pub(in crate::video) fn as_str(self) -> &'static str {
match self {
Self::Film => "film",
Self::Animation => "animation",
Self::Grain => "grain",
Self::Stillimage => "stillimage",
Self::Psnr => "psnr",
Self::Ssim => "ssim",
Self::Fastdecode => "fastdecode",
Self::Zerolatency => "zerolatency",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn h264_profile_should_return_correct_str() {
assert_eq!(H264Profile::Baseline.as_str(), "baseline");
assert_eq!(H264Profile::Main.as_str(), "main");
assert_eq!(H264Profile::High.as_str(), "high");
assert_eq!(H264Profile::High10.as_str(), "high10");
}
#[test]
fn h264_preset_should_return_correct_str() {
assert_eq!(H264Preset::Ultrafast.as_str(), "ultrafast");
assert_eq!(H264Preset::Superfast.as_str(), "superfast");
assert_eq!(H264Preset::Veryfast.as_str(), "veryfast");
assert_eq!(H264Preset::Faster.as_str(), "faster");
assert_eq!(H264Preset::Fast.as_str(), "fast");
assert_eq!(H264Preset::Medium.as_str(), "medium");
assert_eq!(H264Preset::Slow.as_str(), "slow");
assert_eq!(H264Preset::Slower.as_str(), "slower");
assert_eq!(H264Preset::Veryslow.as_str(), "veryslow");
assert_eq!(H264Preset::Placebo.as_str(), "placebo");
}
#[test]
fn h264_tune_should_return_correct_str() {
assert_eq!(H264Tune::Film.as_str(), "film");
assert_eq!(H264Tune::Animation.as_str(), "animation");
assert_eq!(H264Tune::Grain.as_str(), "grain");
assert_eq!(H264Tune::Stillimage.as_str(), "stillimage");
assert_eq!(H264Tune::Psnr.as_str(), "psnr");
assert_eq!(H264Tune::Ssim.as_str(), "ssim");
assert_eq!(H264Tune::Fastdecode.as_str(), "fastdecode");
assert_eq!(H264Tune::Zerolatency.as_str(), "zerolatency");
}
#[test]
fn h264_options_default_should_have_high_profile() {
let opts = H264Options::default();
assert_eq!(opts.profile, H264Profile::High);
assert_eq!(opts.level, None);
assert_eq!(opts.bframes, 2);
assert_eq!(opts.gop_size, 250);
assert_eq!(opts.refs, 3);
assert!(opts.preset.is_none());
assert!(opts.tune.is_none());
}
}