Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to convert h264 stream from annex-b format to AVCC format

Tags:

format

h.264

I need to convert h264 stream from annex-b format to AVCC format.

I tried this to convert from h264 annex-b to AVCC: I extracted the SPS and PPS from the annex stream and created the Extra data. I then looked in the stream for 0x00 0x00 0x00 0x01 (which should be the start of each Nal) and continue looking for another 0x00 0x00 0x00 0x01 (which will be the end of the Nal) then did minus to get the Nal length, then replace the first 0x00 0x00 0x00 0x01 to 0x00 0x00 0x00 [NulSize] but seems that this does not produce valid stream. I then found out that NUL can starts/ends with 0x00 0x00 0x01 so i am little confused.

anyway, I hope someone will be able to write me function that convert from annex-b to AVCC.

Thanks.

like image 415
user3592107 Avatar asked May 01 '14 08:05

user3592107


2 Answers

NALU is basic unit.

Then,

annexb format:

([start code] NALU) | ( [start code] NALU) |

avcc format:

([extradata]) | ([length] NALU) | ([length] NALU) |

In annexb, [start code] may be 0x000001 or 0x00000001.

In avcc, the bytes of [length] depends on NALULengthSizeMinusOne in avcc extradata, the value of [length] depends on the size of following NALU and in both annexb and avcc format, the NALUs are no different.

like image 133
waveacme Avatar answered Nov 09 '22 00:11

waveacme


Start codes are not a fixed size and can be 3 or 4 bytes. Read more here: https://stackoverflow.com/a/24890903/660982

like image 40
szatmary Avatar answered Nov 08 '22 23:11

szatmary