Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 16th March 2009, 21:40   #1  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
AVC Keyframe search

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.
Death KnightŪ is offline   Reply With Quote
Old 16th March 2009, 22:12   #2  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
This document may be helpful:
http://www.itu.int/rec/dologin_pub.a...F-E&type=items

The Bitstream Format is defined in Annex B.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 16th March 2009, 22:27   #3  |  Link
Sharktooth
Mr. Sandman
 
Sharktooth's Avatar
 
Join Date: Sep 2003
Location: Haddonfield, IL
Posts: 11,768
and FCS dont place AVC in AVI...
Sharktooth is offline   Reply With Quote
Old 16th March 2009, 23:35   #4  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
Thanks!
It helps a lot!
Death KnightŪ is offline   Reply With Quote
Old 30th August 2009, 00:08   #5  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
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?
Death KnightŪ is offline   Reply With Quote
Old 30th August 2009, 01:06   #6  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
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?
Guest is offline   Reply With Quote
Old 30th August 2009, 02:49   #7  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
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

Last edited by Death KnightŪ; 30th August 2009 at 03:20.
Death KnightŪ is offline   Reply With Quote
Old 30th August 2009, 03:03   #8  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
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...
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 30th August 2009, 04:20   #9  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by Death KnightŪ View Post
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.
Guest is offline   Reply With Quote
Old 30th August 2009, 14:35   #10  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
I can't find any smaller AVC.
http://rapidshare.com/files/27342378..._Bomb.mkv.html
Death KnightŪ is offline   Reply With Quote
Old 30th August 2009, 15:02   #11  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
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.

Code:
	// 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);
	}

Last edited by Guest; 30th August 2009 at 15:10.
Guest is offline   Reply With Quote
Old 30th August 2009, 17:07   #12  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
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.



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.
Death KnightŪ is offline   Reply With Quote
Old 30th August 2009, 21:06   #13  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
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.

Last edited by Guest; 30th August 2009 at 21:10.
Guest is offline   Reply With Quote
Old 1st September 2009, 00:11   #14  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
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.
Death KnightŪ is offline   Reply With Quote
Old 1st September 2009, 01:59   #15  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by Death KnightŪ View Post
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.
Guest is offline   Reply With Quote
Old 1st September 2009, 10:55   #16  |  Link
Death KnightŪ
Registered User
 
Death KnightŪ's Avatar
 
Join Date: Aug 2005
Location: Istanbul, Turkey
Posts: 66
I have no problems remaining on parsing Nalu now.
Only I think about meaning of SEQ_PARAM. No real problem here.
Death KnightŪ is offline   Reply With Quote
Reply

Tags
avc h264 keyframe


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.