From the discussion in the comments I rephrase your question and split it into two:
I want to extract NAL units from H264 RTP packets in pure java and dump them into an Annex B H264 file.
How do I do that? Is there a library?
The payload of these packets is specified in RFC3984.
I don't know any Java library that performs this out of the box. But implementation is fairly simple as long as the packaging type is not interleaved:
RFC3984 allows three packaging type
- Single NAL unit mode
- Non-interleaved mode
- Interleaved mode
as long as your packet source is sending in single NAL unit mode or non-interleaved mode you can extract the NAL units without any further processing from the packets and dump them to disk with 0x00,0x00,0x00,0x01 as divider between them.
If the packaging type is interleaved you need to put a lot more work into that since than you will have to look into the NALs and re-order them to be in decoding order.
I mux raw Annex B H264 files into an MP4 container in pure Java
You can you use my mp4parser project to generate a MP4 from the Annex B format. Have a look at the H264Example - that should give you an idea on how to use it.