Expand description
A library for parsing and manipulating SubRip Text (SRT) subtitle files.
SRT is a simple, widely-supported subtitle format used by media players, video editors, and streaming platforms. Each subtitle entry consists of:
- A sequential index number
- A timestamp range (start –> end)
- One or more lines of text
§Example
use skrt::{Srt, Timestamp};
// Parse an existing SRT file
let data = r#"1
00:00:01,000 --> 00:00:04,000
Hello, world!
2
00:00:05,000 --> 00:00:08,000
This is a subtitle.
"#;
let srt = Srt::try_parse(data).unwrap();
assert_eq!(2, srt.subtitles().len());
// Or build one programmatically
let mut srt = Srt::new();
srt.add_subtitle(
Timestamp::from_millis(1000).unwrap(),
Timestamp::from_millis(4000).unwrap(),
"Hello, world!".into(),
);
let output = srt.serialize();§Format Details
This crate handles common SRT variations:
- Both LF and CRLF line endings
- Optional UTF-8 BOM at the start of the file
- Trailing whitespace after timestamps
- Files that don’t end with a blank line
Timestamps follow the format HH:MM:SS,mmm where:
HH= hours (00-99)MM= minutes (00-59)SS= seconds (00-59)mmm= milliseconds (000-999)
Structs§
- Srt
- A collection of subtitles representing an SRT file.
- Subtitle
- A single subtitle entry.
- Timestamp
- A timestamp representing a point in time within media.
Enums§
- SrtError
- Error type for SRT parsing and manipulation operations.
Type Aliases§
- Result
- A convenient Result type alias for SRT operations.