Need help writing SEI packet into H.265 stream

91 views Asked by At

I need add sei packet to h265. I need write some data into stream. Can anyone write a simple code to help me? I get a code for h264. can anyone write a similar code to help me?

int fill_sei_packet_h264(unsigned char* packet, int * piPktLen, bool isAnnexb, const char* content, uint32_t size) { if (!piPktLen) return -1;

//
unsigned char* data = (unsigned char*)packet;
unsigned int nalu_size = (unsigned int)get_sei_nalu_size(size);
uint32_t sei_size = nalu_size;
//大端转小端
nalu_size = reversebytes(nalu_size);

//NALU开始码
unsigned int* size_ptr = &nalu_size;
if (isAnnexb)
{
    memcpy(data, start_code, sizeof(unsigned int));
}
else
{
    memcpy(data, size_ptr, sizeof(unsigned int));
}
data += sizeof(unsigned int);

unsigned char* sei = data;
//NAL header
*data++ = 6; //SEI
//sei payload type
*data++ = 5; //unregister
size_t sei_payload_size = size + UUID_SIZE;
//数据长度
while (true)
{
    *data++ = (sei_payload_size >= 0xFF ? 0xFF : (char)sei_payload_size);
    if (sei_payload_size < 0xFF) break;
    sei_payload_size -= 0xFF;
}

//UUID
memcpy(data, uuid, UUID_SIZE);
data += UUID_SIZE;
//数据
memcpy(data, content, size);
data += size;

//tail 截止对齐码
if (sei + sei_size - data == 1)
{
    *data = 0x80;
}
else if (sei + sei_size - data == 2)
{
    *data++ = 0x00;
    *data++ = 0x80;
}

//
if (piPktLen) {
    *piPktLen = data - packet;
}

//
return 0;

}

add sei packet into h265 stream

0

There are 0 answers