use crate::frame::CodecId;
use crate::{MediaFrame, Result};
use async_trait::async_trait;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RenditionSpec {
pub name: String,
pub width: u32,
pub height: u32,
pub video_bitrate_bps: u64,
pub codec: CodecId,
}
impl RenditionSpec {
pub fn new(
name: impl Into<String>,
height: u32,
video_bitrate_bps: u64,
codec: CodecId,
) -> Self {
Self {
name: name.into(),
width: height * 16 / 9,
height,
video_bitrate_bps,
codec,
}
}
}
#[async_trait]
pub trait Transcoder: Send + Sync {
fn id(&self) -> &str;
fn renditions(&self) -> &[RenditionSpec];
async fn transcode(&mut self, frame: MediaFrame) -> Result<Vec<MediaFrame>>;
async fn flush(&mut self) -> Result<Vec<MediaFrame>> {
Ok(Vec::new())
}
}