VideoDecoder icon indicating copy to clipboard operation
VideoDecoder copied to clipboard

NalUnitParser does not seem to parse packets with multiple NAL units

Open MaximKalinin opened this issue 9 months ago • 3 comments

It looks like there is a bug in NalUnitParser class when parsing video packets. Specifically, if a packet contains more than one NAL unit, the parser just considers it as a single unit, resulting in info loss and decoder not working properly (e.g. if the video packets contains sps, pps and idr units, they are treated as a single sps unit).

I see that the code for detecting multiple units separated by the Annex B delimiter is there, it just does not work properly. It could be because the bytes array created in startCode closure expression gets deallocated after the closure ends, so its reference is not quite valid anymore, and contains garbage values (e.g. [0,0,0,0] instead of [0,0,0,1]).

The issue might not be there in the example app because the video packets happen to have only a single NAL unit. However, I was testing with a different setup using a different library to encode the packets, and that library produces multi-unit packets.

I have made a quick fix locally, it works and looks the following:

Image

Do you think it is really a bug and if yes, should I open a PR with the fix?

MaximKalinin avatar Jul 02 '25 12:07 MaximKalinin

Yes, this is a bug, you can submit a PR, thanks

songbihai avatar Jul 30 '25 07:07 songbihai

Here you go @songbihai: https://github.com/songbihai/VideoDecoder/pull/6

MaximKalinin avatar Aug 05 '25 13:08 MaximKalinin

Great, I see you merged the MR @songbihai. Would it be possible to create a new Pods version with that change?

MaximKalinin avatar Sep 09 '25 15:09 MaximKalinin