Skip to main content

scte35_to_hls/
scte35_to_hls.rs

1//! Demonstrate SCTE-35 → HLS `#EXT-X-DATERANGE` conversion.
2//!
3//! Parses a hex `splice_info_section` (Unified Streaming splice ID 2002),
4//! builds a [`Timeline`] with a wall-clock [`TimeAnchor`], and emits the
5//! `#EXT-X-DATERANGE:` tag line.
6//!
7//! Run with:
8//! ```text
9//! cargo run -p timed-metadata --example scte35_to_hls
10//! ```
11
12use timed_metadata::{TimeAnchor, Timeline};
13
14fn main() {
15    // Real Unified Streaming splice: ID 2002, out-of-network, break_duration 24 s.
16    let hex = "FC302100000000000000FFF01005000007D27FEF7F7E0020F580C0000000000088B9661D";
17    let raw = broadcast_common::hex::hex_decode(hex).unwrap();
18
19    // Wall-clock anchor: assume PTS 0 == 2024-01-15T12:00:00.000Z (ms since epoch).
20    let utc_epoch_ms: i64 = 1_705_320_000_000; // 2024-01-15 12:00:00 UTC
21    let anchor = TimeAnchor {
22        pts_90k: 0,
23        utc_epoch_ms,
24    };
25
26    let mut timeline = Timeline::new(anchor);
27
28    // Parse the SCTE-35 section and unroll PTS wrap.
29    let event = timeline.push_scte35(&raw).expect("valid splice");
30
31    // Convert to a DATERANGE.
32    let daterange = timeline.to_daterange(&event).expect("anchor is set");
33
34    println!("Event kind  : {}", event.kind);
35    println!("Event id    : {:?}", event.id);
36    println!(
37        "Duration    : {:?}s",
38        event.duration.map(|d| d.as_seconds_f64())
39    );
40    println!();
41    println!(
42        "{}",
43        daterange.to_tag_line().expect("valid DATERANGE attributes")
44    );
45}