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 33EBE4E533 for ; Wed, 12 Mar 2025 07:06:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F59A68D645; Wed, 12 Mar 2025 09:06:36 +0200 (EET) Received: from out162-62-57-64.mail.qq.com (out162-62-57-64.mail.qq.com [162.62.57.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AED3A68D8E6 for ; Wed, 12 Mar 2025 09:06:29 +0200 (EET) Received: from localhost.localdomain ([111.30.83.130]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 19535A47; Wed, 12 Mar 2025 15:06:21 +0800 X-QQ-mid: xmsmtpt1741763181tv6bigaxw Message-ID: X-QQ-XMAILINFO: NmZCkUihGlO5ksqeIGuoGZGS78vvrazofj2QbGyJtfIOtzZ/2nX8JQgEnpj9Mk +mha/wFDkI9Nh8QVCOiqIiMX6FxQsDwG1+nKCK0net0Zpj+k9Oj7k6DQob5rGDd/QKBFLlRWcgy8 hVqrq3KkeO/gzl/T4M1OKN3BcAXL1vJDv4YYrxq8z+DqAiCGa2VLQHeM6j5YnqOQ2ScNCDD+hRfQ RrOe4iQ4TQTppjJSWC/dGLPTMPmrRHy2322EtYhcqPhym5Zx84fHJDHGjSP8HMa5o8NmCFa+zrhf DnDoao6OBfj/E546Gqq4pXBOx88mOne09KIH2mwfPIVSQGg6274Y+dwA/9hlOTMmUrXCs1UOk7Et lfcQIkdUnNt+JY8fwBBfs6ElUC+PPSXywIOWvG2k9ikY4WH36EEGWM37R2yxHrRfPkutODVepzRC X+ZElRWETB6P2CYmi61ksyE00GgMIaZ8Bq3srsgnSKxnqDb4vZM4g/Zy3Bn6SJgWWRk6nK6Gexqz E4LXnaY3o9DX0aD2U5aA9Mb7HyboGj2TbapcEHYvenPLiKHexZjoqjeagThjfcgyaGDLoHzT8YTr 2QQ+xwBns3ShJGNGzDAImraOG/9VIodKoWHlCFxqdTCFgelZvYTilrAB1EdMdKUtvB0kY/s4M3xO /Ksfp9Y93gCsBHvemcdfWtGwtON6XX7zZehic358HIT4LysRMuAx0OdZdxG1AOP3+jagohu190+J 88hEufJ5cpIoWwpWMLJZTp0ogrQPWo1eW2oXnwoBFkJI0GHlBCsp5Z+wakFAKNGnqAi0He4KvvtL S++HntaXc1RDPvkoV19iMsBmmwU/QFCSJkgyFgEWljBMs4GIAg5t2Jx0W2s/AIwExPcC4YXYSHiY 8IG2RnPpVPszK0qeML5ptCEyI2AW5FtopQIMF7i44usAKm2SNmPi+OJxEEoUtVDa5E3Qev4d1G X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Mar 2025 15:06:18 +0800 X-OQ-MSGID: <20250312070618.18876-1-jacklau1222@qq.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse 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: 11316 add set_hevc_codec_str function refer to hlsenc.c but do some necessary changes Signed-off-by: Jack Lau --- libavformat/dashenc.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d4a6fe0304..04c5b562d5 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -57,6 +57,7 @@ #include "url.h" #include "vpcc.h" #include "dash.h" +#include "nal.h" typedef enum { SEGMENT_TYPE_AUTO = 0, @@ -344,6 +345,84 @@ static void set_vp9_codec_str(AVFormatContext *s, AVCodecParameters *par, return; } +static void set_hevc_codec_str(AVCodecParameters *par, char *str, int size) { + uint8_t *data = par->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 (par->profile != AV_PROFILE_UNKNOWN) + profile = par->profile; + if (par->level != AV_LEVEL_UNKNOWN) + level = par->level; + + /* check the boundary of data which from current position is small than extradata_size */ + while (data && (data - par->extradata + 19) < par->extradata_size) { + /* get HEVC SPS NAL and seek to profile_tier_level */ + if (!(data[0] | data[1] | data[2]) && data[3] == 1 && ((data[4] & 0x7E) == 0x42)) { + 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 */ + remain_size = par->extradata_size - (data - par->extradata); + rbsp_buf = ff_nal_unit_extract_rbsp(data, remain_size, &rbsp_size, 0); + if (!rbsp_buf) + return; + if (rbsp_size < 13) { + av_freep(&rbsp_buf); + break; + } + /* skip sps_video_parameter_set_id u(4), + * sps_max_sub_layers_minus1 u(3), + * 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); + break; + } + data++; + } + if (profile != AV_PROFILE_UNKNOWN && + profile_compatibility != AV_PROFILE_UNKNOWN && + tier != 0 && + level != AV_LEVEL_UNKNOWN && + constraints[0] != '\0') { + av_strlcatf(str, size, ".%d.%x.%c%d.%s", profile, profile_compatibility, tier, level, constraints); + } + return; +} + static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size) { @@ -422,6 +501,8 @@ static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, av_strlcatf(str, size, ".%02x%02x%02x", extradata[1], extradata[2], extradata[3]); av_free(tmpbuf); + } else if (!strcmp(str, "hev1") || !strcmp(str, "hvc1")) { + set_hevc_codec_str(par, str, size); } else if (!strcmp(str, "av01")) { AV1SequenceParameters seq; if (!par->extradata_size) -- 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".