ts-analyzer

Crates.iots-analyzer
lib.rsts-analyzer
version0.2.1
sourcesrc
created_at2024-06-03 02:06:36.329566
updated_at2024-07-29 00:44:08.726891
descriptionA simple library for analyzing packets in MPEG/Transport Stream files.
homepage
repositoryhttps://github.com/GrimOutlook/ts-analyzer
max_upload_size
id1259613
size75,144
Dominic Grimaldi (GrimOutlook)

documentation

https://docs.rs/ts-analyzer

README

ts-analyzer

Crates.io Total Downloads docs.rs Crates.io Version GitHub Repo stars Crates.io License

A library used for analyzing MPEG/Transport Stream files. This library is not intended for encoding, decoding or multiplexing transport streams. It has mainly been created for KLV extraction using klv-reader.

Example

extern crate ts_analyzer;

use std::env;
use ts_analyzer::reader::TSReader;
use std::fs::File;
use std::io::BufReader;

fn main() {
    env_logger::init();
    let filename = env::var("TEST_FILE").expect("Environment variable not set");
    println!("Reading data from {}", filename);

    let f = File::open(filename.clone()).expect("Couldn't open file");
    let buf_reader = BufReader::new(f);
    // Reader must be mutable due to internal state changing to keep track of what packet is to be
    // read next.
    let mut reader = TSReader::new(&filename, buf_reader).expect("Transport Stream file contains no SYNC bytes.");

    let mut packet;
    loop {
        println!("Reading packet");
        // Run through packets until we get to one with a payload.
        packet = reader.next_packet_unchecked() // Read the first TS packet from the file.
                       .expect("No valid TSPacket found"); // Assume that a TSPacket was found in the file.

        if packet.has_payload()  {
            break
        }
    }

    let payload = packet.payload();
    assert!(payload.is_some(), "No payload in packet");
    println!("Payload bytes: {:02X?}", payload.unwrap().data());
}

Goals

  • Parse transport stream packets
    • Parse transport stream packet header
    • Parse transport stream packet adaptation field
    • Parse transport stream packet adaptation extension field
    • Be able to dump raw payload bytes from packet
  • Parse complete payloads from multiple packets
    • Track packets based on PID
    • Concatenate payloads of the same PID based on continuity counter

Reference Material

Commit count: 29

cargo fmt