Commit 6aad90c7ce for ffmpeg
commit 6aad90c7ce844c5a354cf5fa80fc5317a5c6cb05
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Mon Nov 16 20:51:53 2026 -0600
avformat/codecstring: write every HEVC constraint byte
The codec string carries the six general_constraint_indicator_flags
bytes, dot separated, with trailing zero bytes omitted
(ISO/IEC 14496-15). Only the first byte and the high nibble of the
second were written, so later non-zero bytes were lost.
An HEVC string can now reach 40 characters, more than the 32-byte
buffer hlsenc formats it into. Enlarge the buffer, and leave the
attribute out rather than write a truncated string.
diff --git a/libavformat/codecstring.c b/libavformat/codecstring.c
index 570a1de99b..ef9db1259c 100644
--- a/libavformat/codecstring.c
+++ b/libavformat/codecstring.c
@@ -74,7 +74,7 @@ static void parse_hevc_profile_tier_level(const uint8_t *ptl,
size_t constraints_size)
{
uint32_t profile_compatibility_flags;
- uint8_t high_nibble;
+ int constraint_bytes = 6;
/* TIER represents the general_tier_flag, with 'L' indicating the flag is 0,
* and 'H' indicating the flag is 1
@@ -97,10 +97,12 @@ static void parse_hevc_profile_tier_level(const uint8_t *ptl,
* 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 = ptl[6] >> 4;
- snprintf(constraints, constraints_size,
- high_nibble ? "%02x.%x" : "%02x",
- ptl[5], high_nibble);
+ while (constraint_bytes > 1 && !ptl[4 + constraint_bytes])
+ constraint_bytes--;
+ for (int i = 0; i < constraint_bytes; i++)
+ snprintf(constraints + 3 * i, constraints_size - 3 * i,
+ "%02x.", ptl[5 + i]);
+ constraints[3 * constraint_bytes - 1] = '\0';
/* skip 8 + 32 + 4 + 43 + 1 bit */
*level = ptl[11];
}
@@ -152,7 +154,7 @@ int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
uint32_t profile_compatibility = AV_PROFILE_UNKNOWN;
char tier = 0;
int level = AV_LEVEL_UNKNOWN;
- char constraints[8] = "";
+ char constraints[19] = "";
if (par->profile != AV_PROFILE_UNKNOWN)
profile = par->profile;
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d763209ccf..ab529d5431 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -351,7 +351,7 @@ static void set_http_options(AVFormatContext *s, AVDictionary **options, HLSCont
static void write_codec_attr(AVStream *st, VariantStream *vs)
{
int codec_strlen = strlen(vs->codec_attr);
- char attr[32];
+ char attr[64];
AVBPrint buffer;
if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
@@ -361,7 +361,8 @@ static void write_codec_attr(AVStream *st, VariantStream *vs)
av_bprint_init_for_buffer(&buffer, attr, sizeof(attr));
if (ff_make_codec_str(vs->avf, st->codecpar, &st->avg_frame_rate,
- &buffer) < 0)
+ &buffer) < 0 ||
+ !av_bprint_is_complete(&buffer))
goto fail;
// Don't write the same attribute multiple times
diff --git a/libavformat/tests/codecstring.c b/libavformat/tests/codecstring.c
index 58fc422118..bd257dd4d8 100644
--- a/libavformat/tests/codecstring.c
+++ b/libavformat/tests/codecstring.c
@@ -65,6 +65,16 @@ static const uint8_t hevc_hvcc_profile_space[] = {
0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
};
+static const uint8_t hevc_hvcc_constraints[] = {
+ 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x10, 0x00, 0x00, 0x00,
+ 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
+};
+
+static const uint8_t hevc_hvcc_constraints_full[] = {
+ 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x10, 0x20, 0x30, 0x40, 0x50,
+ 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
+};
+
typedef struct TestCase {
const char *name;
enum AVCodecID codec_id;
@@ -98,6 +108,12 @@ static const TestCase cases[] = {
{ "hevc-hvcc-profile-space", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
AV_PROFILE_UNKNOWN, hevc_hvcc_profile_space,
sizeof(hevc_hvcc_profile_space) },
+ { "hevc-hvcc-constraints", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'),
+ AV_PROFILE_UNKNOWN, hevc_hvcc_constraints,
+ sizeof(hevc_hvcc_constraints) },
+ { "hevc-hvcc-constraints-full", AV_CODEC_ID_HEVC,
+ MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
+ hevc_hvcc_constraints_full, sizeof(hevc_hvcc_constraints_full) },
{ "aac-lc", AV_CODEC_ID_AAC, 0,
AV_PROFILE_AAC_LOW, NULL, 0 },
};
diff --git a/tests/ref/fate/codecstring b/tests/ref/fate/codecstring
index 70536e0263..7ef22bd9d7 100644
--- a/tests/ref/fate/codecstring
+++ b/tests/ref/fate/codecstring
@@ -9,4 +9,6 @@ hevc-hvcc-hev1: hev1.1.6.L30.90
hevc-hvcc-version0: hvc1.1.6.L30.90
hevc-hvcc-zeroed: error
hevc-hvcc-profile-space: hvc1.A1.6.L30.90
+hevc-hvcc-constraints: hvc1.1.6.L30.90.00.10
+hevc-hvcc-constraints-full: hvc1.1.6.L30.90.10.20.30.40.50
aac-lc: mp4a.40.2