ralfbiedert / openh264-rs

Idiomatic Rust wrappers around OpenH264.
66 stars 32 forks source link

How do I control the NAL packet size for the Encoder? #47

Open crabdancing opened 3 months ago

crabdancing commented 3 months ago

I'm working on encoding NAL packets over UDP for a (hopefully) low latency 1080p streaming application. As such, I'd prefer to avoid repacketizing them, and keep the packets below the 1050 byte fragmentation limit present. As it stands, I'm seeing NAL packet sizes in excess of 33K bytes, so it's definitely not suitable for my application without being able to tweak this. :P

ralfbiedert commented 3 months ago

Does that refer to a specific NAL unit type? I am not sure H.264 supports something like NAL fragmentation (or if OpenH264 would have such option), but generally I'd expect the size of NALs such as IDRs to be dictated by basic picture settings (resolution, compression, ...), with the resulting size "being what it is".

crabdancing commented 3 months ago

There seems to be options for it. uiMaxNalSize and uiSliceSizeConstraint exist in upstream codebase, though I'm not exactly sure how to use them.

I know certainly that uiSliceMode seems to work, though. Without it, it tries to packetize each and every frame, and I can report that UDPSockets do not like this. But ideally we'd be able to somehow set maximum packet size, which seems possible based on upstream code API?

ralfbiedert commented 3 months ago

Interesting, I wasn't aware of slicing, and haven't used it. I'd certainly accept PRs though to get this to work, and / or expose it through a safe API!