#传输流 # #传输 #视频流 #MPEG #解析器

ts-analyzer

一个用于分析MPEG/传输流文件中数据包的简单库

3个不稳定版本

0.2.1 2024年7月29日
0.2.0 2024年6月7日
0.1.0 2024年6月3日

视频类别中排名第133

Download history 142/week @ 2024-05-30 205/week @ 2024-06-06 4/week @ 2024-06-13 136/week @ 2024-07-25 21/week @ 2024-08-01

每月下载量157

MIT许可

63KB
980 代码行

ts-analyzer

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

用于分析MPEG/传输流文件的库。该库不用于编码、解码或复用传输流。它主要是为使用klv-reader提取KLV而创建的。

示例

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());
}

目标

  • 解析传输流数据包
    • 解析传输流数据包头部
    • 解析传输流数据包适配字段
    • 解析传输流数据包适配扩展字段
    • 能够从数据包中转储原始有效负载字节
  • 解析多个数据包的完整有效负载
    • 基于PID跟踪数据包
    • 根据连续计数器连接相同PID的有效负载

参考资料

依赖项

~1MB
~23K SLoC