0

I'm using avcodec H264 decoder in my project. I receive NAL units from network, stick together NALs from same frame (additional header is added on network layer) and than pass to the decoder. I was wondering if frame sequence number is encoded into NAL unit - it would be logical, as we need the reference to IDR frames.

If this information is present - how can I extract it?

Right now I looking into ITU-T H.264 specification, which is quite complex I can admit. So far I have not found the answer to my question.

Dan Tumaykin
  • 1,213
  • 2
  • 17
  • 37
  • 1
    I am not sure what exactly you are trying to find. If you trying to find out if different NALs correspond to the same frame then you need to read "7.4.1.2.4 Detection of the first VCL NAL unit of a primary coded picture". Pay attention that same frame_num from slice_header is not enough to say that NALs correspond to the same frame. – nobody555 Apr 02 '14 at 17:04
  • Thank you. That was exactly the question - how do I understand that NALs are from the same frame? And in which order should they be in the block passed to the decoder? – Dan Tumaykin Apr 03 '14 at 07:44
  • @nobody555, as far as I can see - frame_num from slice header corresponds perfectly to frame sequence number, and even if it overflows every `MaxFrameNum` it is not a problem - I'll not make frame buffer bigger than that value. Also I'm using Baseline profile, so slice order does not matter, so frame_num should be enough. Am I wrong somewhere? – Dan Tumaykin Apr 03 '14 at 13:42

1 Answers1

2

No. frame_num is not enough (because it can be equal for different frames and not due MaxFrameNum frame overflow). For example, subsequent B-frames can have equal frame_num but different pic_order_cnt_lsb. As I said you need to read "7.4.1.2.4 Detection of the first VCL NAL unit of a primary coded picture" from H.264 spec to find out NALs from different primary coded pictures. And to find out the order of NALs inside one picture you can analyse the value of first_mb_in_slice.

nobody555
  • 2,239
  • 18
  • 18
  • Is it also true for baseline profile, were we have only I and P frames? – Dan Tumaykin Apr 04 '14 at 18:53
  • 1
    Yes, it is possible if we talk in general according to H.264 specs. But would you really see such thing depend from encoder implementation. AFAIK x264 will increase frame_num for every P-frame in such baseline stream but if you will have subsequent IDR-frames than they will have equal frame_num (it should be forced to zero) but will have different idr_pic_id. – nobody555 Apr 05 '14 at 07:32