| Crates.io | pgs-rs |
| lib.rs | pgs-rs |
| version | 0.1.1 |
| created_at | 2025-11-28 02:31:14.143606+00 |
| updated_at | 2025-11-28 02:41:17.902612+00 |
| description | A library for parsing and rendering PGS subtitles |
| homepage | |
| repository | https://github.com/jordansekky/pgs-rs |
| max_upload_size | |
| id | 1954712 |
| size | 26,864 |
A Rust library for parsing and rendering PGS (Presentation Graphic Stream) subtitles, commonly found on Blu-ray discs.
winnow for fast, zero-copy parsing where possible.Add this to your Cargo.toml:
[dependencies]
pgs-rs = "0.1.0"
Here is a basic example of how to load a .sup file, parse it, and iterate through the display sets.
use std::fs;
use pgs_rs::parse::parse_pgs;
use pgs_rs::render::{DisplaySetIterator, render_display_set};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load your PGS data (e.g., from a .sup file)
let mut data = fs::read("subtitles.sup")?;
// Parse the PGS stream
let pgs = parse_pgs(&mut data).expect("Failed to parse PGS");
// Iterate over each DisplaySet
for (i, ds) in DisplaySetIterator::new(&pgs).enumerate() {
if ds.is_empty() {
continue;
}
println!("Rendering Display Set #{}", i);
// Render the display set to an RGBA buffer
match render_display_set(&ds) {
Ok(rgba_buffer) => {
println!("Rendered frame: {}x{}", ds.width, ds.height);
// The buffer contains raw RGBA bytes: [r, g, b, a, r, g, b, a, ...]
// You can save this to an image file using the `image` crate or process it further.
}
Err(e) => eprintln!("Error rendering: {}", e),
}
}
Ok(())
}
This project is licensed under the MIT License.