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.
extern crate klv_uas;
use std::env;
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 mut reader = TSReader::new(f).expect("Transport Stream file contains no SYNC bytes.");
let klv: KlvPacket;
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 = reader.next_payload_unchecked()
// Assume that a payload was found in the file and was successfully parsed.
.expect("No valid payload found");
// 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) => {
println!("Error {:?}", e);
continue
},
};
break
}
println!("Timestamp of KLV packet: {}", klv.precision_time_stamp());
}
- Support parsing all value types from KLV fields.
- int
- int8
- int16
- int32
- uint
- uint8
- uint16
- uint32
- uint64
- IMAPB
- Byte
- DLP
- VLP
- FLP
- Set
- UTF8
TEST_FILE="$HOME/Truck.ts" cargo run --features search --example klv_timestamp
- A sample TS stream with KLV data can be found here.
- The standards for KLV metadata can be found here. Find
MISB ST 0107.X
and clickFILE
. The current link is here but is likely to change. - The standards for the UAS Datalink Local Set can be found here. Find
MISB ST 0601.X
and clickFILE
. The current link is here but is likely to change.