Skip to main content

wedeo_codec/
subtitle.rs

1use wedeo_core::error::Result;
2use wedeo_core::packet::Packet;
3
4/// A single subtitle rectangle/region.
5#[derive(Debug, Clone)]
6pub enum SubtitleRect {
7    /// Bitmap subtitle (e.g., DVD subtitles).
8    Bitmap {
9        x: u32,
10        y: u32,
11        width: u32,
12        height: u32,
13        data: Vec<u8>,
14        palette: Vec<u32>,
15    },
16    /// Text subtitle.
17    Text(String),
18    /// ASS/SSA formatted subtitle.
19    Ass(String),
20}
21
22/// A subtitle event with timing and content.
23#[derive(Debug, Clone)]
24pub struct Subtitle {
25    pub start_display_time: u32,
26    pub end_display_time: u32,
27    pub pts: i64,
28    pub rects: Vec<SubtitleRect>,
29}
30
31/// Subtitle decoder trait.
32pub trait SubtitleDecoder: Send {
33    fn decode(&mut self, packet: &Packet) -> Result<Option<Subtitle>>;
34    fn flush(&mut self);
35}
36
37/// Subtitle encoder trait.
38pub trait SubtitleEncoder: Send {
39    fn encode(&mut self, subtitle: &Subtitle) -> Result<Packet>;
40}