* [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse
@ 2025-03-12 7:06 Jack Lau via ffmpeg-devel
2025-03-27 12:47 ` Jack Lau
2025-03-27 13:19 ` Zhao Zhili
0 siblings, 2 replies; 3+ messages in thread
From: Jack Lau via ffmpeg-devel @ 2025-03-12 7:06 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jack Lau
fix ticket: 11316
add set_hevc_codec_str function refer to hlsenc.c but do some necessary changes
Signed-off-by: Jack Lau <jacklau1222@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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse
2025-03-12 7:06 [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse Jack Lau via ffmpeg-devel
@ 2025-03-27 12:47 ` Jack Lau
2025-03-27 13:19 ` Zhao Zhili
1 sibling, 0 replies; 3+ messages in thread
From: Jack Lau @ 2025-03-27 12:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Mar 12, 2025, at 15:06, Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> wrote:
>
> fix ticket: 11316
> add set_hevc_codec_str function refer to hlsenc.c but do some necessary changes
> Signed-off-by: Jack Lau <jacklau1222@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-request@ffmpeg.org with subject "unsubscribe”.
PING.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse
2025-03-12 7:06 [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse Jack Lau via ffmpeg-devel
2025-03-27 12:47 ` Jack Lau
@ 2025-03-27 13:19 ` Zhao Zhili
1 sibling, 0 replies; 3+ messages in thread
From: Zhao Zhili @ 2025-03-27 13:19 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Mar 12, 2025, at 15:06, Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> wrote:
>
> fix ticket: 11316
> add set_hevc_codec_str function refer to hlsenc.c but do some necessary changes
> Signed-off-by: Jack Lau <jacklau1222@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)
It’s not a good idea to copy-paste a lot of code between hls and dash.
> --
> 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".
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-27 13:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-12 7:06 [FFmpeg-devel] [PATCH] avformat/dashenc: add hevc codec attributes parse Jack Lau via ffmpeg-devel
2025-03-27 12:47 ` Jack Lau
2025-03-27 13:19 ` Zhao Zhili
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git