当前位置: 动力学知识库 > 问答 > 编程问答 >

h.264 - h264: Add user unregistered SEI message

问题描述:

I'm trying to write a NAL unit with a SEI user data message. My code looks like:

typedef struct {

unsigned char type_code;

unsigned char countryCode;

unsigned char countryCodeExtension[2];

unsigned char user_identifier[4];

unsigned char payloadBytes[20];

unsigned char marker_bits;

} userdata_reg_t35;

unsigned char begin[5] = {0x00, 0x00, 0x00, 0x01, 0x06};

unsigned char end[3] = {0x00, sizeof(userdata_reg_t35), 0x80};

userdata_reg_t35 m_userSEIData;

m_userSEIData.countryCode = 0xB5;

m_userSEIData.countryCodeExtension[0] = 0x31;

m_userSEIData.countryCodeExtension[1] = 0x00;

m_userSEIData.user_identifier[0] = 0x34;

m_userSEIData.user_identifier[1] = 0x39;

m_userSEIData.user_identifier[2] = 0x41;

m_userSEIData.user_identifier[3] = 0x47;

m_userSEIData.type_code = 0x03;

m_userSEIData.marker_bits = 0xFF;

sprintf((char*)m_userSEIData.payloadBytes, "%s", "My Payload");

memcpy(target, begin, 5);

memcpy(target + 5, &m_userSEIData, sizeof(userdata_reg_t35));

memcpy(target + 5 + sizeof(userdata_reg_t35), end, 3);

When I playback the file in mplayer or vlc, I receive errors:

[h264 @ 0x7f5860c20720] SEI type 3 truncated at 216

What am I doing wrong?

** EDIT **

I have modified the code after reading http://git.videolan.org/?p=x264.git;a=blob;f=encoder/set.c#l563

static const uint8_t uuid[16] = {0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7,

0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef};

unsigned char begin[7] = {0x00, 0x00, 0x00, 0x01, 0x06, 0x05, 16 + 20};

char szPayload[20];

memset(szPayload, 0, 20);

sprintf(szPayload, "%s", "My payload");

memcpy(target, begin, 7);

memcpy(target + 7, uuid, 16);

memcpy(target + 7 + 16, szPayload, 20);

but I'm still getting the libav error: https://ffmpeg.org/doxygen/2.6/h264__sei_8c_source.html, line #306. What am I still doing wrong?

网友答案:

This does not look good and it does not map well on the H.264 Annex D spec.

You are adding SEI NAL type, then you are expected to add payloadType, payloadSize values - you don't have them. Then you stated you want unregistered SEI message (type 5) and your content more looks like payload type 4 (apparently you are adding captions). So you need to include that and exclude type_code, then it would look about right.

That is, your unneeded type_code 3 goes in place of expected value of 5/4 and then there is no length. VLC stumbles on exactly this...

See H.264 D.1 SEI payload syntax for details.

UPDATE. Your updated code is incorrect [also] for another reason. You are doing Annex B byte stream with start codes and in the same time you are including 20 zero bytes of payload, which under normal conditions should be updated with emulation prevention bytes.

To compare what you get with what x264 produces, simply open x264 output using binary editor and check the SEI NALs, then compare to yours.

分享给朋友:
您可能感兴趣的文章:
随机阅读: