From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 2F8AE4DCA8 for ; Sun, 2 Mar 2025 13:31:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CEF9968E376; Sun, 2 Mar 2025 15:31:09 +0200 (EET) Received: from out203-205-221-149.mail.qq.com (out203-205-221-149.mail.qq.com [203.205.221.149]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AE6868D5EE for ; Sun, 2 Mar 2025 15:31:01 +0200 (EET) Received: from localhost.localdomain ([111.30.83.130]) by newxmesmtplogicsvrszb20-0.qq.com (NewEsmtp) with SMTP id 7B788EF1; Sun, 02 Mar 2025 21:30:55 +0800 X-QQ-mid: xmsmtpt1740922255tge6cn9rw Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9zagfNGhhAM6iVgoEdM3NqsIo1/VbkC8D1c+wQAMaFN2Kbrr3ct dceB1QBoEaVfuiGcKxWlQxxY+8n+MQ5ZXqPV4I5PBowWg4mpP+Fh1TDCU455n166M/JtA2wmxXLt OA0OT/wn+0/EQoeGo/4LZbUIR+RXPCbD1gwyj/2EtrflQXUPhT8w4xrkd2bj/ru28mTZPP25tmFl 3EWh9JYbQeN2lCwLLenIhD46QkEnLenakr4tlBx/ijmXy1HRqmuEAYMgHi494lWGFCy8tZBVblNL xe6bXkK58aFgAtaSbm2703BB/G0Ugmad3BavRWSgMJSkGX6HtQvtTYypsqxSxzxlA66pjy+SfCqE LS6ZlUDctmKMqBzsdZ3sXED9CWNY3bmFtV0r+RFBIS/SXwznQK5zzSdzbw/wn4EkfFIYaAgoF9+Q rViuASbYQVLsQ4dhlVHcoTaOikYQ8YWLYp6P4xD/u5CkF36tSDSRDWQmhh1fnQ/qzQph+KkgYRiJ A3W6DLbFLthUoHxLyuCYAECZG3kfaZPGEdMwrvGOg9gjRjl1/g30lBmQ+Y9HVXI33rSmJghJHp+x G56HgBX6whmEyqK30VWeodZ4bzLUXipSRNwdoxBQatxrnbWDb4mwKOJIIZiSle7RUGxIkvjhiECJ pP45QKS+ywWEGQAQ5t+R2lFc3RuCnEk04Z8i7qkljXUmwxen26EzZXk8jmSZpP5+uXkrMNleI8u4 /sUE0dN3IQOnmCvienSpOwXvyeCypb8e2F2dwdAoCuYQ0b1QazMRi/8x2Rs0Uu4irXgQzDzTAahq kYSbLfyT9JMPJOtPkTqJMLvc4IpFHTwf+RnLtNL5NlXcKveZRnAfewtvQ4UN/SGZkaYctMT+zU5l 7TaKV1vF9CUYPV41OIQydmHsOboH0t2Ur7mg1L/kxOnDuW3ANRF3MhxEuySjOOaYPjuPOsBHsQ X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Mar 2025 21:30:47 +0800 X-OQ-MSGID: <20250302133047.28195-1-jacklau1222@qq.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix CODECS Attribute hard code in hevc EXT-X-STREAM-INF X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jack Lau via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Jack Lau Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: fix ticket: 10786 parse the SPS from extradata and get profile_compatibility, tier, constraints which was been hard code before. HEVC CODECS Attribute reference to: ISO/IEC14496-15 Signed-off-by: Jack Lau --- libavformat/hlsenc.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 6148685f40..849130196f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -379,7 +379,10 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { uint8_t *data = st->codecpar->extradata; int profile = AV_PROFILE_UNKNOWN; + uint32_t profile_compatibility = AV_PROFILE_UNKNOWN; + char tier = 0; int level = AV_LEVEL_UNKNOWN; + char constraints[8] = ""; if (st->codecpar->profile != AV_PROFILE_UNKNOWN) profile = st->codecpar->profile; @@ -393,6 +396,8 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) uint8_t *rbsp_buf; int remain_size = 0; int rbsp_size = 0; + uint32_t profile_compatibility_flags = 0; + uint8_t high_nibble = 0; /* skip start code + nalu header */ data += 6; /* process by reference General NAL unit syntax */ @@ -406,8 +411,35 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) } /* skip sps_video_parameter_set_id u(4), * sps_max_sub_layers_minus1 u(3), - * and sps_temporal_id_nesting_flag u(1) */ + * and sps_temporal_id_nesting_flag u(1) + * + * TIER represents the general_tier_flag, with 'L' indicating the flag is 0, + * and 'H' indicating the flag is 1 + */ + tier = (int)(rbsp_buf[1] & 0x20) == 0 ? 'L' : 'H'; profile = rbsp_buf[1] & 0x1f; + /* PROFILE_COMPATIBILITY is general_profile_compatibility_flags, but in reverse bit order, + * in a hexadecimal representation (leading zeroes may be omitted). + */ + profile_compatibility_flags = AV_RB32(rbsp_buf + 2); + /* revise these bits to get the profile compatibility value */ + { + uint32_t x = profile_compatibility_flags; + x = ((x & 0x55555555U) << 1) | ((x >> 1) & 0x55555555U); + x = ((x & 0x33333333U) << 2) | ((x >> 2) & 0x33333333U); + x = ((x & 0x0F0F0F0FU) << 4) | ((x >> 4) & 0x0F0F0F0FU); + x = ((x & 0x00FF00FFU) << 8) | ((x >> 8) & 0x00FF00FFU); + profile_compatibility = (x << 16) | (x >> 16); + } + /* skip 8 + 8 + 32 + * CONSTRAINTS is a hexadecimal representation of the general_constraint_indicator_flags. + * each byte is separated by a '.', and trailing zero bytes may be omitted. + * drop the trailing zero bytes refer to ISO/IEC14496-15. + */ + high_nibble = rbsp_buf[7] >> 4; + snprintf(constraints, sizeof(constraints), + high_nibble ? "%02x.%x" : "%02x", + rbsp_buf[6], high_nibble); /* skip 8 + 8 + 32 + 4 + 43 + 1 bit */ level = rbsp_buf[12]; av_freep(&rbsp_buf); @@ -417,8 +449,11 @@ static void write_codec_attr(AVStream *st, VariantStream *vs) } if (st->codecpar->codec_tag == MKTAG('h','v','c','1') && profile != AV_PROFILE_UNKNOWN && - level != AV_LEVEL_UNKNOWN) { - snprintf(attr, sizeof(attr), "%s.%d.4.L%d.B01", av_fourcc2str(st->codecpar->codec_tag), profile, level); + profile_compatibility != AV_PROFILE_UNKNOWN && + tier != 0 && + level != AV_LEVEL_UNKNOWN && + constraints[0] != '\0') { + snprintf(attr, sizeof(attr), "%s.%d.%x.%c%d.%s", av_fourcc2str(st->codecpar->codec_tag), profile, profile_compatibility, tier, level, constraints); } else goto fail; } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { -- 2.47.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".