Skip to main content

Crate timed_metadata

Crate timed_metadata 

Source
Expand description

§timed-metadata

crates.io docs.rs License

Convert DPI / timed-metadata signalling between SCTE-35, HLS EXT-X-DATERANGE and DASH emsg losslessly, plus a first-pass CEA-608/708 and EBU Teletext to WebVTT cue extractor. no_std + alloc, independently versioned.

[dependencies]
timed-metadata = "0.10"

§What it does / what it does not

Ad-insertion and segmentation signalling travels in three formats across an OTT chain: SCTE-35 splice_info_section in MPEG-2 TS, #EXT-X-DATERANGE in an HLS playlist, and an inband emsg box in MP4/CMAF. This crate translates between them. The original splice_info_section bytes travel verbatim (DATERANGE SCTE35-* hex, emsg message_data), so nothing is re-encoded or interpreted away. A stateful Timeline session adds a wall-clock anchor and 33-bit PTS wrap-unrolling.

It does not parse SCTE-35 itself (that is scte35-splice), does not parse or write full HLS playlists (broadcast-hls) or full MP4 files, and does not make ad decisions. The caption half is lossy by design (no placement or styling, see below); for SRT/TTML conversion use caption-convert, which wraps these extractors.

§Standards supported

StandardEditionScopeStatusNotes
ANSI/SCTE 352023r1 (via scte35-splice)splice_info_section carried verbatim and parsed for id/time/durationFull
IETF RFC 8216 / draft-pantos-hls-rfc8216bisdraft -22 (1 May 2026, private/specs-verified/ietf/specs/ietf_draft_pantos_hls_rfc8216bis.txt)§4.4.5.1 EXT-X-DATERANGE attributes incl. SCTE35-CMD/OUT/INPartialSCTE-35 to DATERANGE and DATERANGE tag-line parse/render; no DATERANGE to SCTE-35 event conversion.
ANSI/SCTE 214-3unverified (not vendored)§8.3.3 inband emsg, scheme urn:scte:scte35:2013:binFull for the binary schemePart number settled from DASH-IF IOP v4.3 §5.4.3 (see convert/emsg.rs). The MPD EventStream XML form (SCTE 214-1) is not implemented.
ISO/IEC 23009-1 (via mp4-emsg)unverified§5.10.3.3 Event Message Box, v0 <-> v1 re-timingFullemsg_to_v0 / emsg_to_v1
W3C WebVTT + RFC 8216 §3.5curated rules: private/specs-verified/rules/webvtt-rules.mdcue syntax, X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:<n>PartialNo cue settings (line/position/align), no styling tags.
ANSI/CTA-608-E, CTA-708-E (decode in cc-data)CTA-608-E, CTA-708-E (CTA not vendored; 708 cross-source: GY/T 270-2013, vendored, a Chinese adaptation)CC1 pop-on/roll-up/paint-on, 708 service windowsPartialfeature cc-data; documented losses in webvtt module docs.
ETSI EN 300 706 Enhanced Teletext (decode here) / EN 301 775 §4.5 (carriage in dvb-vbi)V1.2.1 of each (private/specs-md/INDEX.md)Level-1 subtitle pages, Hamming-8/4, odd parity, English national optionPartialfeature teletext; no enhancement packets, no styling, English-only national option (private/specs-verified/dvb/timed-metadata/teletext-subtitles.md).

§Conversion matrix

From \ ToHLS EXT-X-DATERANGEDASH emsgSCTE-35 bytes
SCTE-35 splice_info_sectionTimeline::to_daterange / convert::scte35_to_daterangeTimeline::to_emsg / convert::scte35_to_emsgidentity
DASH emsg (SCTE-35 scheme)not providedemsg_to_v0 / emsg_to_v1 (re-time)convert::emsg_to_scte35
HLS EXT-X-DATERANGEtag-line DateRange::parse_tag_line / to_tag_linenot providedraw bytes available on the parsed DateRange; no typed conversion
Caption sourceOutputFeatureStatus
CEA-608 CC1 (cc_data() triplets)WebVTT cuescc-dataPartial (lossy)
CEA-708 service (cc_data() triplets)WebVTT cuescc-dataPartial (lossy)
EBU Teletext Level-1 subtitle pageWebVTT cuesteletextPartial (lossy)
Cue listWebVTT document or HLS segment (X-TIMESTAMP-MAP)alwaysFull

§Feature flags

FeatureDefaultDescription
stdonEnable std in all dependencies. Without it: no_std + alloc, all conversions still available.
serdeoffSerialize/Deserialize on public types where supported.
cc-dataoffCEA-608/708 to WebVTT cue extraction (webvtt::Cea608CueExtractor, Cea708CueExtractor).
teletextoffEBU Teletext (EN 300 706) to WebVTT cue extraction (webvtt::TeletextCueExtractor, webvtt::teletext).

serde is opt-in and off by default; enable it explicitly:

timed-metadata = { version = "0.10", features = ["serde"] }

§Quick start

use mp4_emsg::PresentationTime;
use timed_metadata::convert::{EmsgConfig, emsg_to_scte35};
use timed_metadata::{TimeAnchor, Timeline};

// A real Unified Streaming splice_info_section (splice id 2002, 24 s break).
let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
let raw: Vec<u8> = (0..hex.len())
    .step_by(2)
    .map(|i| u8::from_str_radix(&hex[i..i + 2], 16).unwrap())
    .collect();

// Wall-clock anchor: PTS 0 == 2024-01-15T12:00:00 UTC.
let anchor = TimeAnchor { pts_90k: 0, utc_epoch_ms: 1_705_320_000_000 };
let mut timeline = Timeline::with_anchor(anchor);
let event = timeline.push_scte35(&raw).unwrap();

// Edge 1: SCTE-35 -> HLS EXT-X-DATERANGE.
let line = timeline.to_daterange(&event).unwrap().to_tag_line().unwrap();
assert!(line.starts_with("#EXT-X-DATERANGE:"));
assert!(line.contains("SCTE35-"));

// Edge 2: SCTE-35 -> DASH emsg, and Edge 3: back to the verbatim section.
let cfg = EmsgConfig {
    timescale: 90_000,
    presentation: PresentationTime::Delta(0),
    event_duration: 2_160_000, // 24 s * 90000
    value: "34".to_string(),
    id: event.id.unwrap_or(0),
};
let emsg = timeline.to_emsg(&event, &cfg).unwrap();
assert_eq!(emsg_to_scte35(&emsg).unwrap(), raw);

§What is implemented

  • convert: pure functions scte35_to_daterange, scte35_to_emsg, emsg_to_scte35, emsg_to_v0, emsg_to_v1; EmsgConfig, SegmentTiming.
  • Timeline / TimeAnchor: stateful session, PTS to UTC mapping, 33-bit PTS wrap-unroll via broadcast_common::clock33; RFC 3339 output through jiff (out-of-range instants clamp rather than print odd years).
  • DateRange: typed EXT-X-DATERANGE with checked rendering (to_tag_line returns Result: ID/CLASS containing ", CR or LF, and NaN / negative durations, are rejected) built on broadcast-hls’s shared attribute-list tokenizer.
  • TimedEvent: neutral event (EventKind, id, media time and duration, source payload).
  • webvtt: Cue, write_document, write_segment, cue_block, shared text helpers (parse_timestamp, format_timestamp_with, unescape_payload, normalize_line_endings, …) used by caption-convert too; extractors behind features. Extractors never emit zero-length cues.

§Design notes

  • Lossless carriage: SCTE-35 bytes are never re-encoded.
  • Error is #[non_exhaustive]; the crate is #![forbid(unsafe_code)] and no_std + alloc without std.
  • Hostile-input hardening: checked time arithmetic, a clock33 tripwire test.
  • Caption conversion is lossy and documents every loss; no round trip is claimed.

Depends on scte35-splice, mp4-emsg, broadcast-hls, broadcast-common, and optionally cc-data / dvb-vbi. Used by caption-convert (caption half), transmux, hls-runtime, media-plane, multimux, media-doctor and compliance-probe.

§MSRV and licence

Rust 1.95.0. MIT OR Apache-2.0.

Re-exports§

pub use anchor::TimeAnchor;
pub use daterange::DateRange;
pub use error::Error;
pub use error::Result;
pub use event::EventKind;
pub use event::MediaDuration;
pub use event::MediaTime;
pub use event::SourcePayload;
pub use event::TimedEvent;
pub use timeline::Timeline;

Modules§

anchor
Media-time ↔ wall-clock mapping for conversions that cross into UTC.
convert
Pure conversion functions (the foundation layer).
daterange
HLS EXT-X-DATERANGE model + (de)serialization.
error
Crate error type.
event
Canonical timed-metadata event (the hub of the hub-and-spoke model).
timeline
Stateful conversion session: holds the wall-clock anchor and unrolls 33-bit PTS wrap across a stream of events.
webvtt
CEA-608/708 -> WebVTT cue conversion (issue #568).

Constants§

PTS_HZ
MPEG-2 Systems 90 kHz system-clock rate: the unit of PTS/DTS and of the 33-bit PCR/ESCR/SCR base (ISO/IEC 13818-1 §2.4.3.5 / §2.4.3.7).