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 CE0484BA45 for ; Sun, 2 Mar 2025 07:47:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D4A068E243; Sun, 2 Mar 2025 09:47:22 +0200 (EET) Received: from out203-205-221-209.mail.qq.com (out203-205-221-209.mail.qq.com [203.205.221.209]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 347E068D224 for ; Sun, 2 Mar 2025 09:47:13 +0200 (EET) Received: from localhost.localdomain ([111.30.83.130]) by newxmesmtplogicsvrszgpua8-1.qq.com (NewEsmtp) with SMTP id BC5132D0; Sun, 02 Mar 2025 15:47:05 +0800 X-QQ-mid: xmsmtpt1740901625tol16w3jh Message-ID: X-QQ-XMAILINFO: Nci1v0XuD9lFiEMUcdq8X98UZO7WpHy42/53+MxO0OI1j7/70aFx8BsPg0+Qvi CEP8PSbdf3wSV/SgiUTCaDAyAqo7PifLCf0WyhYJW7Me33/jG4sIR+/QfWSbxgmSozMigPXSCVtK ZmswRPCrF7BRvahGuQOy00Kq6zP2awNdwsf+27Hm++1y98sYO2dc+XnzuvR7rDiKyCQmmVbDcV0Q qkUWrEnbycCG1wiBvzmfEiiip0W5oYbaKooPOEnqihlWh9MSGIfUZjQcyxwFZr4nel7StWIqgw0T UcxG4akqPeR52zg12bwHRXUdbmo5jAsLIyh1BA0EyLXzg8V9goiMtSyjMBSCJ6Zc/djBU83GACBN mrhP+j2TWvKWcHMV/e2gbGP9c1KqsZEbdeOVYTmDz5k14FDUdCSVBN5Uqau6UfhFAfj7pAHIABmq aiifOp/AK5jv8V2Ft1MSbgNohfG+9e4YiinDkana04Ir0gEyk+aZoOaANXHa8pi014sHEQ9Qu86Y 0efy7gj7I3hvrrvV1gCJdj7IQLuR7qHjfW8UWVQjXJ0vvQp+hl1N/WwhbpbQhwIfYN3exPLqe6Bg VravjZPZ9Y1U9rhKp3OVRP5qdgI/DsOi0kWlwDlXzc89a9b/iKdpg6v/LnuRvhdWQtMecTfvdgq0 OUHAv3CyfWFB7UoS/j25IIeoFZBY60HTW4O3lc/gtf+9GwzOJyUgKbZj9EFtuCh38qi/iAMlY//d uP+de6npnGgTtIs0m4iaRHdZFUNeLujKJNMtkVl4HOGlL9B5nCjt/FONyqwZSvfR5i0ol5D/00F+ MOU3jZX3g5OVQ2z2DshBjMu3E5KDU1w32uKHaAtcRIz+sF2OWqOUAbORHT7pE65xV4q/fIkMrTgL d92DjUI207RuF1Tdo6TzDJM+8M850P5a+u+uiEuPsesTVp/YHoXuk= X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Mar 2025 15:47:01 +0800 X-OQ-MSGID: <20250302074701.30855-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 | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 6148685f40..be7a78021a 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[5] = "0"; 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,31 @@ 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 = (rbsp_buf[2] << 24) | (rbsp_buf[3] << 16) | (rbsp_buf[4] << 8) | rbsp_buf[5]; + /* revise these bits to get the profile compatibility value */ + for (int i = 0; i < 32; i++) { + profile_compatibility = (profile_compatibility << 1) | (profile_compatibility_flags & 1); + profile_compatibility_flags >>= 1; + } + /* 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 +445,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 && + strcmp(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".