Comments (3)
Thanks for the code @karcsesz - I expanded on it a bit to create examples/dump.rs
.
from h264-reader.
Thank you for this! I need to integrate it into my attempt, which works I think but I suspect I didn't do this completely 100% accurately...
https://github.com/groovybits/rsllm/blob/main/src/mpegts.rs#L432
I haven't hooked it up yet, it's attempting to combine AI with the MpegTS "probe" for higher level decisions / analysis potentially (custom models). Had implemented it first here which is hooked up and a pcap into this and the mpegts/scte35 readers of yours...
https://github.com/groovybits/rscap/blob/main/src/bin/probe.rs#L834
This was tricky to figure out, yet seems to get the data, I haven't finished these to a point of using the data but it does print it out and seems correct for the most part (I think a few issues come from needing to refactor it with this example logic in dump.rs you posted!)
Thank you!!!
from h264-reader.
I've managed to make it work like this:
// First we have to create a context to keep track of SPS and PPS NALs that we receive. It *needs* to be persistent through all parsing
let mut stream_context = Context::new();
// Then we prepare an AnnexBReader to handle the parsed data
let mut reader = AnnexBReader::accumulate(|nal: RefNal<'_>| {
// We only ever want to parse complete NALs.
// You can filter for the specific types of NALs you're
// interested in and NalInterest::Ignore the rest here.
//
// If a NAL is incomplete, trying to read its data will result in a WouldBlock.
if !nal.is_complete() {
return NalInterest::Buffer;
}
// Parse the NAL header, so we know what the NAL type is
let nal_header = nal.header().unwrap();
let nal_unit_type = nal_header.nal_unit_type();
// Decode the NAL types that we're interested in
match nal_unit_type {
UnitType::SeqParameterSet => {
let data = SeqParameterSet::from_bits(nal.rbsp_bits()).unwrap();
// Don't forget to tell stream_context that we have a new SPS.
// If you want to handle it separately, you can clone the struct before passing along,
// But if you only care about it when a slice calls for it, you don't have to handle it here.
stream_context.put_seq_param_set(data);
}
UnitType::PicParameterSet => {
// Same as when parsing an SPS, except it borrows the stream context so it can pick out
// the SPS that this PPS references
let data = PicParameterSet::from_bits(&stream_context, nal.rbsp_bits()).unwrap();
// Same as with an SPS, tell the context that we've found a PPS
stream_context.put_pic_param_set(data);
}
// Let's handle a random slice type too to see how that works
UnitType::SliceLayerWithoutPartitioningIdr => {
let mut bits = nal.rbsp_bits();
// We can parse the slice header, and it will give us:
let (header, // The header of the slice
seq_params, // A borrow of the SPS...
pic_params // ...and PPS activated by the header
) = SliceHeader::from_bits(&stream_context,
&mut bits, // takes a mutable borrow so the body parser can continue from where this ended
nal_header).unwrap();
// I don't think any slice data parsers are implemented right now.
}
other => {println!("Unhandled {other:?}")}
}
NalInterest::Ignore
});
// Push data. Doesn't have to be aligned in any way. You can push multiple times for a single NAL, or send an entire file in at once.
reader.push(data);
// If we're sure that the entire current NAL has been pushed, then we can call this to signal
// that the parser should immediately stop waiting for a new NAL marker.
reader.reset();
from h264-reader.
Related Issues (20)
- Work out how to support h265 syntax without duplicating lots of code HOT 1
- NalSwitch crash when forbidden zero bit set HOT 2
- Fuzzing: OOM in HrdParameters::read_cpb_specs() HOT 1
- release HOT 4
- has_more_rbsp_data is broken / fix trailing bits handling HOT 1
- release? HOT 1
- [Q] Install for those not familiar with Rust HOT 2
- Make SliceHeader fields pub? HOT 5
- Create simpler facades for decoding steps HOT 10
- Maybe wrong constants in PicScalingMatrix HOT 3
- It looks like VuiParameter parsing is slightly off HOT 7
- Parse SeqParameterSet fail with RbspReaderError(RemainingData) HOT 1
- Missing bounds-checks for VUI Bitstream Restriction Syntax Elements HOT 3
- Wrong Bounds Check for pic_parameter_set_id HOT 4
- Incorrect Parsing of Explicit Assignment Slice Groups
- Panic from 'attempt to add with overflow' in qs_y calculation HOT 1
- Fields of `h264_reader::nal::slice::SliceHeader` are not `pub` HOT 1
- Reader example HOT 1
- convenience methods? HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from h264-reader.