Skip to content

nuts: Rust library to parse MPEG Transport Streams.

License

Notifications You must be signed in to change notification settings

alessandrod/nuts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nuts 🥜

A Rust library to parse MPEG Transport Streams.

Early stages but the bulk of the format is implemented and parsing is pretty robust. There are no major known bugs and as it is today the crate includes enough functionality to implement fully functional parsers and demuxers.

The API is still unstable and is going to change.

Build Status License: MIT

Installation

Add nuts to your Cargo.toml:

[dependencies]
nuts = "0.1"

Documentation

The reference documentation is at http://docs.rs/nuts

Example

This example implements a function called dump which parses all the packets from a transport stream file and prints out some fields. For a similar but more complete example, see src/examples/nuts-dump.rs.

use nuts::ts;
use std::fs::File;

fn dump(filename: &str) {
    let file = File::open(filename).unwrap();
    let mut parser = ts::ReaderParser::new(file);
    loop {
        match parser.parse() {
            Ok(Some((input, (packet, data)))) => match data {
                ts::Data::PSI(s) => println!("found PSI: {:?}", s),
                ts::Data::PES(pes_packet, payload) => println!(
                    "found PES packet, pid: {}, size: {}",
                    packet.pid,
                    payload.len()
                ),
                ts::Data::Data(payload) => println!(
                    "found payload packet, pid: {}, size: {}",
                    packet.pid,
                    payload.len()
                ),
            },
            Ok(None) => break,
            Err(e) => {
                if let Err(e) = parser.recover(e) {
                    println!("error: {}", e);
                    break;
                }
            }
        }
    }
}

About

nuts: Rust library to parse MPEG Transport Streams.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages