GithubHelp home page GithubHelp logo

grimoutlook / ts-analyzer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 77 KB

A simple library for analyzing packets in MPEG/Transport Stream files.

Home Page: https://crates.io/crates/ts-analyzer

License: MIT License

Rust 100.00%
mpeg mpegts parser ts video-processing

ts-analyzer's Introduction

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

ts-analyzer's People

Contributors

grimoutlook avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ahenshaw

ts-analyzer's Issues

Adaptation field skipping

It appears that there is a bug in the code to skip over an adaptation field (if present). You read the field length and then increment the read_idx by that value. However, you need to skip over one more byte in order to accommodate the length field itself. So, line 70 of packet.rs should be:
read_idx += af.adaptation_field_length() as usize + 1;

Would you like me to submit a merge request or would you prefer to just make that small change?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.