View Full Version : AVC Keyframe search
Death KnightŪ
16th March 2009, 21:40
Hi. I wanted to identify key frames in AVC steam. Specially in AVI file.
In MPEG4-ASP, there is a flag (first byte) that indicates if its key frame or not.
In MPEG4-AVC, first byte is always 0x01000000.
How can I get information about h264 format? Specially about how its frames constructed.
Thank you.
LoRd_MuldeR
16th March 2009, 22:12
This document may be helpful:
http://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.264-200711-I!!PDF-E&type=items
The Bitstream Format is defined in Annex B.
Sharktooth
16th March 2009, 22:27
and FCS dont place AVC in AVI...
Death KnightŪ
16th March 2009, 23:35
Thanks!
It helps a lot! :)
:thanks:
Death KnightŪ
30th August 2009, 01:08
I think I am in trouble.
I detect some of keys but I don't understand its logic.
0x00 0x00 0x00 0x17 0x67 -> IDR frame OK
0x00 0x00 0x00 0x18 0x67 -> This is IDR too.
I study sheet that you linked,
But those frames not comfort "0x000001" or "0x00000001" start_code_prefix_one_3bytes.
I inspect some codes but I didn't understand.
Could you indicate that where I am making mistake?
I am thinking that 00 00 00 18 conform with specsheet but dividing bytes from half not came logic to me. Do you know anything about this frames?
neuron2
30th August 2009, 02:06
Looks like you haven't extracted the data correctly. You have to look just at the elementary stream when you parse. Have you demuxed, or are you trying to parse an AVI directly?
Death KnightŪ
30th August 2009, 03:49
I am trying to parse in AVI directly.
Those are RAW AVC frame beginnings in AVI. 00dc[4byte frame size ] then [0x00 0x00 0x00 0x17 0x67 ....]
But this also true for MKV. I got same values on MKV SimpleBlock or Blocks [0x00 0x00 0x00 0x17 0x67 ....]
Now which part is "start code prefix" or where is nal_ref_idc.
I think data[4]=0x67 is 7 is nal_unit_type
LoRd_MuldeR
30th August 2009, 04:03
If the AVC stream is in AVI, then it's not raw! You need to parse the RIFF/AVI first and extract the actual "raw" AVC data. Then you can parse the AVC bitstream...
neuron2
30th August 2009, 05:20
But this also true for MKV. I got same values on MKV SimpleBlock or Blocks [0x00 0x00 0x00 0x17 0x67 ....]
Now which part is "start code prefix" or where is nal_ref_idc.
I think data[4]=0x67 is 7 is nal_unit_type Post a link to a short MKV and I'll show you the proper parsing.
Death KnightŪ
30th August 2009, 15:35
I can't find any smaller AVC.
http://rapidshare.com/files/273423786/Atomic_tsar__Bomb.mkv.html
neuron2
30th August 2009, 16:02
First, NALU type 5 is an IDR, not 7.
Second, in MKV files, the NALUs are NOT delimited per Annex B, i.e., they do not use the 00 00 00 01 start code. Instead there is a 4-byte count that gives the length of the NALU. So you find the next NALU by jumping forward according to the count, instead of parsing for Annex B start codes.
Here's a little code fragment from my MKV support in DGAVCIndexNV that converts the MKV NALU to an Annex B NALU for further processing.
// Convert to Annex B NALUs.
// b points to the buffer holding the MKV frame data.
p = b;
while (p < (unsigned char *) b + FrameSize)
{
nalu_len = (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
p[0] = 0;
p[1] = 0;
p[2] = 0;
p[3] = 1;
p += (nalu_len + 4);
}
Death KnightŪ
30th August 2009, 18:07
Things became more clear. Thanks for that.
I am unaware that a AVC frame could have some other marks. I didn't understand SEQ_PARAM indicates this.
I parsed one AVC MKV frame. Which start with SEQ_PARAM I believe...
A0 BlockGroup
A1 Block then 4 byte block header, painted with purple.
Nalu sizes are in red.
http://img143.imageshack.us/img143/1364/nalu.jpg (http://img143.imageshack.us/i/nalu.jpg/)
Now, for this MKV frame, it include 3 NALU, and their types are sequentially 7 (SEQ_PARAM), 8 (PIC_PARAM) then 5 (IDR_SLICE), right?
I wish I understand correctly.
neuron2
30th August 2009, 22:06
Yes, you have it correct now.
>I didn't understand SEQ_PARAM indicates this.
Not sure what you mean by this. There's nothing in the syntax (that I know of) to indicate what NALU delimitation is used. I just know that in MKV this method is used.
If you want to post an AVI example, we can analyze that as well. But I think you have the idea.
Death KnightŪ
1st September 2009, 01:11
I thought SEQ_PARAM indicate that;
there is NALU sequence in this frame, there are more than one NALU for this frame.
I checked some AVI. That uses same pattern with MKV. I think I converted that AVIs from MKV. Other AVIs follow Annex B pattern.
Thanks for the help.
neuron2
1st September 2009, 02:59
I thought SEQ_PARAM indicate that;
there is NALU sequence in this frame, there are more than one NALU for this frame. Are you talking about an SPS? It's a NALU itself so you have a chicken and egg problem if you have to parse it to know how to parse NALUs.
So, specifically, with reference to the spec, what are you referring to? Or is this just something you overheard on a bus? :)
And you're welcome. Happy to help you any time.
Death KnightŪ
1st September 2009, 11:55
I have no problems remaining on parsing Nalu now.
Only I think about meaning of SEQ_PARAM. No real problem here. :)
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.