SCTE-35 Library
A Rust library for creating and parsing SCTE-35 (Society of Cable Telecommunications Engineers) messages with built-in CRC validation. SCTE-35 is a standard for inserting cue messages into video streams, commonly used for ad insertion points in broadcast television.
Features
- Builder Pattern API - Type-safe builder pattern for creating SCTE-35 messages from scratch with validation
- Serde support - Serialize/deserialize SCTE-35 messages to/from JSON and other formats (enabled by default)
- CRC validation - Built-in CRC-32 validation using MPEG-2 algorithm (enabled by default)
- Human-readable UPID parsing - Full support for 18 standard UPID types with intelligent formatting
- Human-readable segmentation types - Complete set of 48 standard segmentation types with descriptive names
- Segmentation descriptor parsing - Complete parsing of segmentation descriptors including UPID data
- Minimal dependencies - Only the
crccrate for validation (optional) andserdefor serialization (optional) - Full SCTE-35 parsing - Supports all major SCTE-35 command types
- Bit-level precision - Accurate parsing of bit-packed SCTE-35 messages
- Optional CLI tool - Command-line interface for parsing base64-encoded messages with text and JSON output formats
- Type-safe - Strongly typed representations of all SCTE-35 structures
- Data integrity - Detects corrupted or tampered SCTE-35 messages
Installation
With All Features (Default)
Add this to your Cargo.toml:
[]
= "0.2.0"
This includes both CRC validation and serde support.
Without Serde Support
If you don't need JSON serialization:
[]
= { = "0.2.0", = false, = ["crc-validation"] }
Minimal (No CRC or Serde)
For a minimal library without CRC validation or serde:
[]
= { = "0.2.0", = false }
With CLI Tool (Automatically includes CRC validation)
To include the command-line tool, enable the cli feature:
[]
= { = "0.2.0", = ["cli"] }
Or install the CLI tool directly:
Note: The CLI feature automatically enables CRC validation to provide complete message diagnostics.
Usage
Library Usage
use ;
use Duration;
// Your SCTE-35 message as bytes (example message)
let scte35_bytes = vec!;
match parse_splice_info_section
CRC Validation
By default, the library validates CRC-32 checksums in SCTE-35 messages to ensure data integrity:
use ;
// Example SCTE-35 message bytes
let scte35_bytes = vec!;
// Parse with automatic CRC validation (default behavior)
match parse_splice_info_section
// Validate CRC independently
match validate_scte35_crc
// Validate using the parsed section
if let Ok = parse_splice_info_section
Duration Conversion
SCTE-35 time values are represented as 90kHz clock ticks. This library provides convenient conversion to Rust's std::time::Duration:
use BreakDuration;
use Duration;
// Create a break duration of 30 seconds (30 * 90000 ticks)
let break_duration = BreakDuration ;
// Convert using Into trait
let duration: Duration = .into;
assert_eq!;
// Or use the method directly
let duration2 = break_duration.to_duration;
assert_eq!;
Serde Support (JSON Serialization)
The library includes built-in serde support for serializing/deserializing SCTE-35 messages:
use parse_splice_info_section;
use serde_json;
// Parse SCTE-35 message
let scte35_bytes = vec!;
if let Ok = parse_splice_info_section
The serde implementation includes:
- Binary data as base64: All raw bytes (private commands, UPID data, alignment bits) are encoded as base64 strings
- Human-readable enums: Segmentation types and UPID types include both numeric values and descriptions
- Time duration info: PTS times and durations include both raw ticks and human-readable formats
- Computed fields: Segmentation descriptors include parsed UPID strings when available
Example JSON output:
Segmentation Types
The library provides human-readable segmentation types that correspond to the numeric IDs in SCTE-35 messages:
use ;
// Work with segmentation types directly
let seg_type = ProviderAdvertisementStart;
println!;
// Convert from numeric ID (useful when parsing)
let seg_type = from_id;
assert_eq!;
assert_eq!;
// Example: Parse a message and check segmentation descriptors
let scte35_bytes = vec!;
if let Ok = parse_splice_info_section
Supported Segmentation Types
The library supports all standard SCTE-35 segmentation types including:
Program Boundaries:
- Program Start/End
- Program Early Termination
- Program Breakaway/Resumption
- Program Runover (Planned/Unplanned)
- Program Overlap Start
- Program Blackout Override
- Program Join
Content Segments:
- Chapter Start/End
- Break Start/End
- Content Identification
Advertisement Opportunities:
- Provider/Distributor Advertisement Start/End
- Provider/Distributor Placement Opportunity Start/End
- Provider/Distributor Overlay Placement Opportunity Start/End
- Provider/Distributor Promo Start/End
- Provider/Distributor Ad Block Start/End
Special Events:
- Unscheduled Event Start/End
- Alternate Content Opportunity Start/End
- Network Start/End
Builder Pattern API (Creating SCTE-35 Messages)
The library includes a comprehensive builder pattern API for creating SCTE-35 messages from scratch with type safety and validation:
# use *;
# use SegmentationType;
# use Duration;
#
Creating Time Signals with Segmentation Descriptors
# use *;
# use SegmentationType;
# use Duration;
#
Component-Level Splice Operations
# use *;
# use Duration;
#
Advanced Segmentation with Delivery Restrictions
# use *;
# use SegmentationType;
#
Comprehensive UPID Support
The builder API supports all SCTE-35 UPID types with validation:
# use *;
#
Error Handling and Validation
The builder API provides comprehensive validation with clear error messages:
# use *;
# use SegmentationType;
# use Duration;
#
Builder Features
- Type Safety: Compile-time prevention of invalid message states
- Validation: Runtime validation with descriptive error messages
- Ergonomic API: Fluent interface with sensible defaults
- Spec Compliance: Automatic handling of reserved fields and constraints
- Complete Coverage: Builders for all major SCTE-35 structures
See the builder_demo example for more comprehensive usage examples.
CLI Usage
When built with the cli feature, you can parse base64-encoded SCTE-35 messages with multiple output formats:
# Text output (default)
# JSON output
# Or with long flag
# Get help
Example output with splice insert command and break duration:
Successfully parsed SpliceInfoSection:
Table ID: 252
Section Length: 47
Protocol Version: 0
Splice Command Type: 5
Splice Command Length: 20
Splice Command: SpliceInsert
Splice Event ID: 0x4800008f
Splice Event Cancel: 0
Out of Network: 1
Program Splice Flag: 1
Duration Flag: 1
Splice Immediate Flag: 0
Splice Time PTS: 0x07369c02e
Splice Time: 21514.559089 seconds
Break Duration:
Auto Return: 1
Duration: 0x00052ccf5 (60.293567 seconds)
Unique Program ID: 0
Avail Num: 0
Avails Expected: 0
Descriptor Loop Length: 10
Number of Descriptors: 1
Unknown Descriptor:
Tag: 0x00
Length: 8
Content: "CUEI 5"
CRC-32: 0x62DBA30A ✓ (Valid)
CLI Output Formats
The CLI supports two output formats:
- Text format (default): Human-readable format with detailed field descriptions
- JSON format: Structured JSON output for programmatic use
JSON output includes the complete parsed structure with CRC validation results:
Supported SCTE-35 Commands
- SpliceNull - Null command
- SpliceSchedule - Scheduled splice events
- SpliceInsert - Immediate or scheduled ad insertion points
- TimeSignal - Time synchronization signals
- BandwidthReservation - Bandwidth allocation commands
- PrivateCommand - Private/custom commands
CRC Validation
By default, the library validates CRC-32 checksums in SCTE-35 messages to ensure data integrity. This feature can be disabled if needed:
With CRC Validation (Default)
[]
= "0.2.0"
Without CRC Validation (Library only)
[]
= { = "0.2.0", = false }
With CLI Tool (Automatically includes CRC validation)
[]
= { = "0.2.0", = ["cli"] }
Note: The CLI feature automatically enables CRC validation to provide complete message diagnostics.
Benefits of CRC Validation
- Data Integrity: Ensures SCTE-35 messages haven't been corrupted during transmission
- Security: Helps detect tampered messages
- Debugging: Identifies parsing issues vs. data corruption
- Standards Compliance: Follows SCTE-35 specification requirements
- Flexibility: Optional feature allows users to choose performance vs. validation trade-offs
API Documentation
Full API documentation is available at docs.rs or can be generated locally:
Main Functions
parse_splice_info_section(buffer: &[u8]) -> Result<SpliceInfoSection, io::Error>
Parses a complete SCTE-35 splice information section from a byte buffer. Automatically validates CRC-32 when the crc-validation feature is enabled.
validate_scte35_crc(buffer: &[u8]) -> Result<bool, io::Error>
Validates the CRC-32 checksum of an SCTE-35 message independently. Returns Ok(true) if valid, Ok(false) if invalid or CRC validation is disabled.
Data Structures
SpliceInfoSection
The top-level structure containing all SCTE-35 message fields:
table_id: Table identifier (should be 0xFC for SCTE-35)section_length: Length of the sectionprotocol_version: SCTE-35 protocol versionsplice_command_type: Type of splice commandsplice_command: The actual command data (enum)descriptor_loop_length: Length of descriptorssplice_descriptors: List of splice descriptorscrc_32: CRC32 checksum
SpliceCommand
An enum representing different SCTE-35 command types:
SpliceNullSpliceSchedule(SpliceSchedule)SpliceInsert(SpliceInsert)TimeSignal(TimeSignal)BandwidthReservation(BandwidthReservation)PrivateCommand(PrivateCommand)Unknown
Building from Source
Build Library Only
Build with CLI Tool
Run Tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.