fix ticket: 11316 add set_hevc_codec_str function refer to hlsenc.c but do some necessary changes Signed-off-by: Jack Lau <jacklau1...@qq.com> --- 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-requ...@ffmpeg.org with subject "unsubscribe".