How to populate avcC box when encoding fmp4 file with H264 data?

0

my h264 frame just have I/P frame.

The avcC box I filled in is as follows, but it cannot play with the VLC player (the timestamp runs but there is no image).

AVC Decoder Configuration Record :

Start offset 511 (0X000001FF)

Box size 39 (0X00000027)

Box type avcC (0X61766343)

Detailed-Information :

Configuration version 1 (0X00000001)

AVC profile indication Main = 77 (0X0000004D)

AVC profile compatibility 0 (0X00000000)

AVC level indication 42 (0X0000002A)

NAL Unit length size 3 (0X00000003)

Num sequence parameter sets 1 (0X00000001)

Sequence parameter set (0) 0x67 0x4d 0x00 0x2a 0x96 0x35 0xc0 0xf0 0x04 0x4f 0xcb 0x37 0x01 0x01 0x01 0x02

Num picture parameter sets 1 (0X00000001)

Picture parameter set (0) 0x68 0xee 0x3c 0x80

H264 IDR FRAME( SPS PPS SEI):

unsigned char IDR_NALU[] = { 0x00,0x00,0x00,0x01, 0x67,0x4D,0x00,0x2A, 0x96,0x35,0xC0,0xF0, 0x04,0x4F,0xCB,0x37, 0x01,0x01,0x01,0x02, 0x00,0x00,0x00,0x01, 0x68,0xEE,0x3C,0x80, 0x00,0x00,0x00,0x01, 0x06,0xE5,0x01,0x2E, 0x80/I frame data is omitted/ };

I think my avcC box is wrongly filled, but I don't know how to fill it correctly. Which master can help me

mp4
asked on Stack Overflow Jan 3, 2019 by YuanDa.Yu • edited Jan 3, 2019 by szatmary

1 Answer

0

Here is some pseudo code on how to write the content of the avcC box:

//  Version
Write(0x1);

//  Profile
Write(sps[0].data[1]);

//  Compatibility
Write(sps[0].data[2]);

//  level
Write(sps[0].data[3]);

// Reserved (6 bits), NAL Unit length size - 1 (2 bits)
Write(0xFC | 3);

//  Reserved (3 bits), num of SPS (5 bits)
Write(0xE0 | 1);

// 2 bytes for length of SPS
WriteWord(sps[0].size);

//  Data of SPS
for (size_t i = 0; i < sps[0].size(); ++i)
{
    Write(sps[0].data[i]);
}

// Number of PPS
Write(&b, pps.size());

for (size_t i = 0; i < pps.size(); ++i)
{
    // 2 bytes for length of PPS
    WriteWord(pps[i].size);

    for (size_t j = 0; j < pps[i].size; ++j)
    {
        //  Data of PPS
        Write (pps[i].data[j]);
    }
}
answered on Stack Overflow Jan 3, 2019 by Markus Schumann

User contributions licensed under CC BY-SA 3.0