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 1F45A4DCEE for ; Mon, 3 Mar 2025 01:38:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3B37968E462; Mon, 3 Mar 2025 03:38:19 +0200 (EET) Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21E8D68E460 for ; Mon, 3 Mar 2025 03:38:10 +0200 (EET) Received: from localhost.localdomain ([111.30.83.130]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 985A3CE1; Mon, 03 Mar 2025 09:38:05 +0800 X-QQ-mid: xmsmtpt1740965885tkq8423bv Message-ID: X-QQ-XMAILINFO: NtvpdyJXE1j909gTFaDweXZdIpFG61RcajLwvs/60d++OJMklA6Bl46U3DtnZJ pcYwJPtERY2n97W2CX+HDCqKenxRw7XE0v0HFU0cKWWQ7zBwHJcmGfeRpFrCdjKkb/4udR+A2YES Mx91F7iKRFucLSJfInaNWMsj/r1RXp6FOOC3IJ6qHJtt8QcRJkOV0Th5eWxDz2q6FXHXj1eQ3twD hipH4hwg+yirw707YpnCReI2Q0MYE/x+u868cncVzkbT/2jDsCkI3w1zCgkIyAdy192Ak8/6bKzP nuFbDXCSHDUtsFZiVhWPramHPm0kbH8MeweVWZSfBjVHdy8OVDEuqFVQkzh+8PEPxfFYQD6zrCAO lAg1XBZZ6V3V5Ko7aOLaTGbnUp2f1xjg9kTe0WpL824GlCsq3HKC8YK9DcO+VW2DBDF6RA9B/eZo O7ENe14NrhTHbFybRv0D39VmeBLzYqsxLjqBNMaN5bKOQ+VFlFVsDA0tISiJQGQ8im75uU677bj1 cp7WBtAQI0trPXkONxjuzmURspgQbEYXI8+rOc6jJVO9GL1HBNXg8ozlUhAYq5DifAuIJ43krx+/ T3rAerj10MY5F1ApT1I+xNCPWBYEumJwMXycvvQiP/OAWfcY0GLzPxvS5xaph+7WT5CE4en81NJa JPxvx47hZTjxL6jsDxg1r4NnKUBUuE++REv0/9l6SlBdQDdx7Lbn3GyqDECafFI54g7iNDtssLx2 XNi2PPJJb7wHmis0Z0LJNGncoSadM0KEiArgbJENSgFA76HDGn0m0MufJPaxOTZkMBKsAeOVPPek Cx3DxfgrKKpd2N5L/9aGxyj3MBj1N3NfO5tWieSI+8wUyszuJonfjT3aGNV+rKoyNkhuBItevqVU nz30TcpE9ibpTJrN/FXw3mLgkPHzV3mz2Q4HW4YQyFvNhy/5S4ewM63jl+BV6xLoATMiAjH7AESr 9Yk97WX/1D+ccyyZ0N4JJIJDiCgqNeqbuMvFeEA1qOeR9QQBUugw== X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Mar 2025 09:38:03 +0800 X-OQ-MSGID: <20250303013803.20224-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 | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 6148685f40..c6ffdb99e5 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,32 @@ 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 = (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 */ + profile_compatibility_flags = ((profile_compatibility_flags & 0x55555555U) << 1) | ((profile_compatibility_flags >> 1) & 0x55555555U); + profile_compatibility_flags = ((profile_compatibility_flags & 0x33333333U) << 2) | ((profile_compatibility_flags >> 2) & 0x33333333U); + profile_compatibility_flags = ((profile_compatibility_flags & 0x0F0F0F0FU) << 4) | ((profile_compatibility_flags >> 4) & 0x0F0F0F0FU); + profile_compatibility_flags = ((profile_compatibility_flags & 0x00FF00FFU) << 8) | ((profile_compatibility_flags >> 8) & 0x00FF00FFU); + profile_compatibility = (profile_compatibility_flags << 16) | (profile_compatibility_flags >> 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 +446,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".