Crates.io | klv-uas |
lib.rs | klv-uas |
version | 0.1.1 |
source | src |
created_at | 2024-07-29 02:03:57.406465 |
updated_at | 2024-07-29 02:39:54.992864 |
description | A simple library for parsing UAS KLV data from raw data. |
homepage | |
repository | https://github.com/GrimOutlook/klv-uas |
max_upload_size | |
id | 1318432 |
size | 55,311 |
A library for extracting KLV data from transport stream packet payloads. This library is not indented to be used for injecting KLV data into video streams.
Currently, you must enable the feature ignore_incomplete
. I want the user to understand that several of the datatypes
cannot be parsed correctly quite yet, so they must manually allow this.
extern crate klv_uas;
use std::env;
use klv_uas::tag::Tag;
use ts_analyzer::reader::TSReader;
use std::fs::File;
use std::io::BufReader;
use klv_uas::klv_packet::KlvPacket;
fn main() {
env_logger::init();
let filename = env::var("TEST_FILE").expect("Environment variable not set");
let f = File::open(filename.clone()).expect("Couldn't open file");
let buf_reader = BufReader::new(f);
let mut reader = TSReader::new(&*filename, buf_reader).expect("Transport Stream file contains no SYNC bytes.");
reader.add_tracked_pid(258);
let klv;
loop {
// Get a payload from the reader. The `unchecked` in the method name means that if an error
// is hit then `Some(payload)` is returned rather than `Ok(Some(payload))` in order to reduce
// `.unwrap()` (or other) calls.
let payload = match reader.next_payload() {
Ok(payload) => payload.expect("Payload is None"),
Err(e) => panic!("Could not get payload due to error: {}", e),
};
// Try to parse a UAS LS KLV packet from the payload that was found. This will likely only
// work if you have the `search` feature enabled as the UAS LS KLV record does not start at
// the first byte of the payload.
klv = match KlvPacket::from_bytes(payload) {
Ok(klv) => klv,
Err(e) => {
continue
},
};
break
}
println!("Timestamp of KLV packet: {:?}", klv.get(Tag::PrecisionTimeStamp).unwrap());
}
TEST_FILE="$HOME/Truck.ts" cargo run --features search --example klv_timestamp
MISB ST 0107.X
and click FILE
. The current link is here but is likely to change.MISB ST 0601.X
and click FILE
. The current link is here but is likely to change.