iso_bmff/types.rs
1//! Freestanding track/Sample types (no Mediaway dependency).
2
3#![forbid(unsafe_code)]
4
5pub use bytes::Bytes;
6
7/// Integer rational timebase (`num / den` seconds).
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct Rational {
10 /// Numerator.
11 pub num: u64,
12 /// Denominator (non-zero for valid timebases).
13 pub den: u32,
14}
15
16impl Rational {
17 /// Construct a rational.
18 #[must_use]
19 pub const fn new(num: u64, den: u32) -> Self {
20 Self { num, den }
21 }
22}
23
24/// Codec identity for a track.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
26#[non_exhaustive]
27pub enum Codec {
28 /// H.264 / AVC.
29 H264,
30 /// HEVC / H.265.
31 Hevc,
32 /// AV1.
33 Av1,
34 /// VP9.
35 Vp9,
36 /// AAC.
37 Aac,
38 /// Opus.
39 Opus,
40 /// `WebVTT`.
41 WebVtt,
42 /// Tx3g.
43 Tx3g,
44}
45
46/// Track / stream description from `moov` (or mux registration).
47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct Track {
49 /// 0-based track id.
50 pub id: u32,
51 /// Codec.
52 pub codec: Codec,
53 /// Media timebase.
54 pub time_base: Rational,
55 /// Video width (0 for audio).
56 pub width: u32,
57 /// Video height (0 for audio).
58 pub height: u32,
59 /// Codec config (e.g. AVCC).
60 pub extra_data: Bytes,
61}
62
63/// One compressed sample.
64#[derive(Debug, Clone, PartialEq, Eq)]
65pub struct Sample {
66 /// Track id.
67 pub stream_id: u32,
68 /// Presentation timestamp (media timescale; may be negative after edit-list remap).
69 pub pts: i64,
70 /// Decode timestamp (media timescale; may be negative after edit-list remap).
71 pub dts: i64,
72 /// Duration.
73 pub duration: u64,
74 /// Sync / keyframe.
75 pub is_keyframe: bool,
76 /// Outside the active edit window (decode dependency / padding). Decoders may skip.
77 pub is_discard: bool,
78 /// Payload bytes.
79 pub payload: Bytes,
80}