| Crates.io | skrt |
| lib.rs | skrt |
| version | 0.1.1 |
| created_at | 2026-01-20 01:53:23.817804+00 |
| updated_at | 2026-01-20 01:57:44.753971+00 |
| description | Lightweight, zero-copy SubRip Text (SRT) subtitle library for Rust - std only, no dependencies |
| homepage | https://github.com/smackysnacks/skrt |
| repository | https://github.com/smackysnacks/skrt |
| max_upload_size | |
| id | 2055651 |
| size | 41,408 |
A fast, zero-copy parser and serializer for SubRip Text (SRT) subtitle files in Rust.
Add skrt to your Cargo.toml:
[dependencies]
skrt = "0.1"
use skrt::Srt;
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();
for subtitle in srt.iter() {
println!("[{}] {}", subtitle.start(), subtitle.text());
}
use skrt::{Srt, Timestamp};
let mut srt = Srt::new();
srt.add_subtitle(
Timestamp::from_millis(1000).unwrap(),
Timestamp::from_millis(4000).unwrap(),
"First subtitle".into(),
);
srt.add_subtitle(
Timestamp::from_millis(5000).unwrap(),
Timestamp::from_millis(8000).unwrap(),
"Second subtitle".into(),
);
let output = srt.serialize();
println!("{output}");
use skrt::Srt;
let data = "1\n00:00:01,000 --> 00:00:04,000\nHello\n\n";
let mut srt = Srt::try_parse(data).unwrap();
// Shift all subtitles forward by 5 seconds
for sub in srt.iter_mut() {
sub.set_start(sub.start().shift_millis(5000).unwrap());
sub.set_end(sub.end().shift_millis(5000).unwrap());
}
println!("{}", srt.serialize());
use skrt::Timestamp;
let ts = Timestamp::from_millis(5025000).unwrap(); // 1h 23m 45s
assert_eq!("01:23:45,000", ts.to_string());
assert_eq!(5025000, ts.to_millis());
// Timestamps are comparable
let ts2 = Timestamp::from_millis(5025500).unwrap();
assert!(ts < ts2);
SRT files consist of subtitle blocks separated by blank lines. Each block contains:
This crate handles common real-world variations:
Install cargo-fuzz with cargo +nightly install cargo-fuzz, then cd fuzz && cargo +nightly fuzz run -j $(grep -c processor /proc/cpuinfo) parse_srt.