Log in

View Full Version : H264 NAL slice_header decode


raydon
21st November 2009, 15:33
Hi everyone. I am currently developing a utility for importing non-native video to the Humax Foxsat HDR. (The first public release is already available). I want to improve on H264 support and I need a simple method to decode the slice_type fom a NAL unit slice_header. I don't want to use a full implementation of bitstream class and exp-golomb decode. Ideally I just want to read the first few bytes of the NAL payload and decode first_mb_in_slice then the slice_type code. Here is an example of what I mean. These are the first few bytes of a non-IDR NAL unit containing an I-slice(type 7). 00 00 01 61 88 C3 3B 51 11 62 67 3F FB 14 82 74. As I see it the first byte of the payload is byte 5 (88) Converting this and next two bytes (C3 & 3B) into a bitstream gives 100010001100001100111011. The exp-golomb coded number for 7 is 001000 and I would have expected to see this pattern somewhere in these first few bytes. Have I got this wrong ? Can anyone with a better understanding please explain what I am missing here, and show me an example of how to retrieve the code 7 from these bytes?

Reimar
21st November 2009, 23:05
First, a full exp-golomb decoding should not be more than a few lines of code, at least when it does not have to be fast and you don't need to process more that a few bytes.
Second, if you need to decode first_mb_in_slice, you probably won't be able to get around that. Though usually you can just assume that the only case you care about is first_mb_in_slice == 0, you probably should check that.
Next, your bitstream example parses as
1 -> 0
0001000 -> 7
so I don't see your problem...

raydon
22nd November 2009, 12:27
Thanks, Reimar, Couldn't see what was under my nose. I was miscounting the leading zeros. (not subtracting 1 from count)