The branch, master has been updated
via 586898dc1fc60d5aad39bb939c5d6255a0062fc3 (commit)
via 900b77b1b7dfe0ddefbc329226f7ecf6aa55efd3 (commit)
via ee22107c67463ee8a3bec417a9318fa4c2653b9e (commit)
via d015382f4a80d533b0809f0267cc1be95f61a7bb (commit)
from 549b45459e4c2e1819edefc15fdf116f0689e7d3 (commit)
- Log -----------------------------------------------------------------
commit 586898dc1fc60d5aad39bb939c5d6255a0062fc3
Author: Martin Storsjö <[email protected]>
AuthorDate: Mon Oct 27 13:30:42 2025 +0200
Commit: Martin Storsjö <[email protected]>
CommitDate: Sat Nov 8 21:19:31 2025 +0000
avformat: Make ff_make_codec_str output to an AVBPrint object
diff --git a/libavformat/codecstring.c b/libavformat/codecstring.c
index 773c37f6b5..12e0fd22c8 100644
--- a/libavformat/codecstring.c
+++ b/libavformat/codecstring.c
@@ -20,6 +20,7 @@
*/
#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/rational.h"
@@ -44,36 +45,32 @@ static const struct codec_string {
};
static void set_vp9_codec_str(void *logctx, const AVCodecParameters *par,
- const AVRational *frame_rate, char *str, int
size) {
+ const AVRational *frame_rate, AVBPrint *out)
+{
VPCC vpcc;
int ret = ff_isom_get_vpcc_features(logctx, par, NULL, 0, frame_rate,
&vpcc);
if (ret == 0) {
- snprintf(str, size, "vp09.%02d.%02d.%02d",
- vpcc.profile, vpcc.level, vpcc.bitdepth);
+ av_bprintf(out, "vp09.%02d.%02d.%02d",
+ vpcc.profile, vpcc.level, vpcc.bitdepth);
} else {
// Default to just vp9 in case of error while finding out profile or
level
av_log(logctx, AV_LOG_WARNING, "Could not find VP9 profile and/or
level\n");
- av_strlcpy(str, "vp9", size);
+ av_bprintf(out, "vp9");
}
}
int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
- const AVRational *frame_rate, char *str, size_t size)
+ const AVRational *frame_rate, struct AVBPrint *out)
{
int i;
- if (size < 5)
- return AVERROR(EINVAL);
-
- str[0] = '\0';
-
// common Webm codecs are not part of RFC 6381
for (i = 0; codecs[i].id != AV_CODEC_ID_NONE; i++)
if (codecs[i].id == par->codec_id) {
if (codecs[i].id == AV_CODEC_ID_VP9) {
- set_vp9_codec_str(logctx, par, frame_rate, str, size);
+ set_vp9_codec_str(logctx, par, frame_rate, out);
} else {
- av_strlcpy(str, codecs[i].str, size);
+ av_bprintf(out, "%s", codecs[i].str);
}
return 0;
}
@@ -92,8 +89,7 @@ int ff_make_codec_str(void *logctx, const AVCodecParameters
*par,
p = &data[1];
else
return AVERROR(EINVAL);
- snprintf(str, size,
- "avc1.%02x%02x%02x", p[0], p[1], p[2]);
+ av_bprintf(out, "avc1.%02x%02x%02x", p[0], p[1], p[2]);
} else {
return AVERROR(EINVAL);
}
@@ -172,7 +168,9 @@ int ff_make_codec_str(void *logctx, const AVCodecParameters
*par,
tier != 0 &&
level != AV_LEVEL_UNKNOWN &&
constraints[0] != '\0') {
- snprintf(str, size, "%s.%d.%x.%c%d.%s",
av_fourcc2str(par->codec_tag), profile, profile_compatibility, tier, level,
constraints);
+ av_bprintf(out, "%s.%d.%x.%c%d.%s",
+ av_fourcc2str(par->codec_tag), profile,
+ profile_compatibility, tier, level, constraints);
} else
return AVERROR(EINVAL);
} else if (par->codec_id == AV_CODEC_ID_AV1) {
@@ -184,23 +182,23 @@ int ff_make_codec_str(void *logctx, const
AVCodecParameters *par,
if ((err = ff_av1_parse_seq_header(&seq, par->extradata,
par->extradata_size)) < 0)
return err;
- snprintf(str, size, "av01.%01u.%02u%s.%02u",
+ av_bprintf(out, "av01.%01u.%02u%s.%02u",
seq.profile, seq.level, seq.tier ? "H" : "M",
seq.bitdepth);
if (seq.color_description_present_flag)
- av_strlcatf(str, size, ".%01u.%01u%01u%01u.%02u.%02u.%02u.%01u",
- seq.monochrome,
- seq.chroma_subsampling_x, seq.chroma_subsampling_y,
seq.chroma_sample_position,
- seq.color_primaries, seq.transfer_characteristics,
seq.matrix_coefficients,
- seq.color_range);
+ av_bprintf(out, ".%01u.%01u%01u%01u.%02u.%02u.%02u.%01u",
+ seq.monochrome,
+ seq.chroma_subsampling_x, seq.chroma_subsampling_y,
seq.chroma_sample_position,
+ seq.color_primaries, seq.transfer_characteristics,
seq.matrix_coefficients,
+ seq.color_range);
} else if (par->codec_id == AV_CODEC_ID_MPEG4) {
// RFC 6381
- snprintf(str, size, "mp4v.20");
+ av_bprintf(out, "mp4v.20");
// Unimplemented, should output ProfileLevelIndication as a decimal
number
av_log(logctx, AV_LOG_WARNING, "Incomplete RFC 6381 codec string for
mp4v\n");
} else if (par->codec_id == AV_CODEC_ID_MP2) {
- snprintf(str, size, "mp4a.40.33");
+ av_bprintf(out, "mp4a.40.33");
} else if (par->codec_id == AV_CODEC_ID_MP3) {
- snprintf(str, size, "mp4a.40.34");
+ av_bprintf(out, "mp4a.40.34");
} else if (par->codec_id == AV_CODEC_ID_AAC) {
// RFC 6381
int aot = 2;
@@ -210,11 +208,11 @@ int ff_make_codec_str(void *logctx, const
AVCodecParameters *par,
aot = ((AV_RB16(par->extradata) >> 5) & 0x3f) + 32;
} else if (par->profile != AV_PROFILE_UNKNOWN)
aot = par->profile + 1;
- snprintf(str, size, "mp4a.40.%d", aot);
+ av_bprintf(out, "mp4a.40.%d", aot);
} else if (par->codec_id == AV_CODEC_ID_AC3) {
- snprintf(str, size, "ac-3");
+ av_bprintf(out, "ac-3");
} else if (par->codec_id == AV_CODEC_ID_EAC3) {
- snprintf(str, size, "ec-3");
+ av_bprintf(out, "ec-3");
} else {
return AVERROR(EINVAL);
}
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 636e770450..da7725fc3f 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -1361,6 +1361,7 @@ static int dash_init(AVFormatContext *s)
AVStream *st;
AVDictionary *opts = NULL;
char filename[1024];
+ AVBPrint buffer;
os->bit_rate = s->streams[i]->codecpar->bit_rate;
if (!os->bit_rate) {
@@ -1574,8 +1575,8 @@ static int dash_init(AVFormatContext *s)
c->has_video = 1;
}
- ff_make_codec_str(s, st->codecpar, &st->avg_frame_rate, os->codec_str,
- sizeof(os->codec_str));
+ av_bprint_init_for_buffer(&buffer, os->codec_str,
sizeof(os->codec_str));
+ ff_make_codec_str(s, st->codecpar, &st->avg_frame_rate, &buffer);
os->first_pts = AV_NOPTS_VALUE;
os->max_pts = AV_NOPTS_VALUE;
os->last_dts = AV_NOPTS_VALUE;
@@ -1697,6 +1698,7 @@ static int update_stream_extradata(AVFormatContext *s,
OutputStream *os,
uint8_t *extradata;
size_t extradata_size;
int ret;
+ AVBPrint buffer;
if (par->extradata_size)
return 0;
@@ -1711,7 +1713,8 @@ static int update_stream_extradata(AVFormatContext *s,
OutputStream *os,
memcpy(par->extradata, extradata, extradata_size);
- ff_make_codec_str(s, par, frame_rate, os->codec_str,
sizeof(os->codec_str));
+ av_bprint_init_for_buffer(&buffer, os->codec_str, sizeof(os->codec_str));
+ ff_make_codec_str(s, par, frame_rate, &buffer);
return 0;
}
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 8e36887e06..7105404d1e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -350,14 +350,16 @@ static void write_codec_attr(AVStream *st, VariantStream
*vs)
{
int codec_strlen = strlen(vs->codec_attr);
char attr[32];
+ AVBPrint buffer;
if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
return;
if (vs->attr_status == CODEC_ATTRIBUTE_WILL_NOT_BE_WRITTEN)
return;
+ av_bprint_init_for_buffer(&buffer, attr, sizeof(attr));
if (ff_make_codec_str(vs->avf, st->codecpar, &st->avg_frame_rate,
- attr, sizeof(attr)) < 0)
+ &buffer) < 0)
goto fail;
// Don't write the same attribute multiple times
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 54b2ad6c79..d32a3376cc 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -673,6 +673,6 @@ int ff_parse_opts_from_query_string(void *obj, const char
*str, int allow_unkown
* @return <0 on error
*/
int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
- const AVRational *frame_rate, char *str, size_t size);
+ const AVRational *frame_rate, struct AVBPrint *out);
#endif /* AVFORMAT_INTERNAL_H */
commit 900b77b1b7dfe0ddefbc329226f7ecf6aa55efd3
Author: Martin Storsjö <[email protected]>
AuthorDate: Thu Oct 23 13:20:54 2025 +0300
Commit: Martin Storsjö <[email protected]>
CommitDate: Sat Nov 8 21:19:31 2025 +0000
hlsenc, dashenc: Share the routine for generating a codec string
The one in dashenc was added in
fe5e6e34c05e274f98528be4f77f3c474473f977, while the one in hlsenc
was added later in 0afa171f25bc9b613a77328182e54d6e781269d3. Both
have had various additions on top; merge both implementations
into one shared. (Notable additions in
060e74e2a970bb12ab138cfff5aaff8d132ffc65,
1cf2f040e34bbfedde60ff3d91b2f7b770aca85b,
a2b1dd0ce301450a47c972745a6b33c4c273aa5d and
797f0b27c175022d896e46db4ac2873e3e0a70af.)
For H264/avc1, use the implementation from hlsenc (which doesn't
use temporary allocations). For most other codecs, use the
only implementation from whichever had one.
The original dashenc implementation tried to be generic based
on RFC 6381, looking up codec tags in ff_codec_movvideo_tags
or ff_codec_movaudio_tags, and doing specific extra additions
for "mp4a" and "mp4v". In practice, only AV_CODEC_ID_AAC
and AV_CODEC_ID_MPEG4 ever mapped to these; simplify this to
a more straightforward codec id based handling, and merge
with the AAC profile based code from hlsenc.
There's a slight behaviour difference from the old one in
dashenc; if there's no code for a specific codec ID, we previously
just output what we matched from the mov tag tables, but now
we won't output anything. But most commonly used codecs in
DASH should be covered here.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index ed93458f03..86177af2f4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -179,7 +179,7 @@ OBJS-$(CONFIG_CONCAT_DEMUXER) += concatdec.o
OBJS-$(CONFIG_CRC_MUXER) += crcenc.o
OBJS-$(CONFIG_DATA_DEMUXER) += rawdec.o
OBJS-$(CONFIG_DATA_MUXER) += rawenc.o
-OBJS-$(CONFIG_DASH_MUXER) += dash.o dashenc.o hlsplaylist.o
+OBJS-$(CONFIG_DASH_MUXER) += dash.o dashenc.o hlsplaylist.o
codecstring.o
OBJS-$(CONFIG_DASH_DEMUXER) += dash.o dashdec.o
OBJS-$(CONFIG_DAUD_DEMUXER) += dauddec.o
OBJS-$(CONFIG_DAUD_MUXER) += daudenc.o
@@ -267,7 +267,7 @@ OBJS-$(CONFIG_HEVC_MUXER) += rawenc.o
OBJS-$(CONFIG_EVC_DEMUXER) += evcdec.o rawdec.o
OBJS-$(CONFIG_EVC_MUXER) += rawenc.o
OBJS-$(CONFIG_HLS_DEMUXER) += hls.o hls_sample_encryption.o
-OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o
+OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o
codecstring.o
OBJS-$(CONFIG_HNM_DEMUXER) += hnm.o
OBJS-$(CONFIG_HXVS_DEMUXER) += hxvs.o
OBJS-$(CONFIG_IAMF_DEMUXER) += iamfdec.o
diff --git a/libavformat/codecstring.c b/libavformat/codecstring.c
new file mode 100644
index 0000000000..773c37f6b5
--- /dev/null
+++ b/libavformat/codecstring.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2014 Martin Storsjo
+ * Copyright (c) 2018 Akamai Technologies, Inc.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem.h"
+#include "libavutil/rational.h"
+
+#include "av1.h"
+#include "avc.h"
+#include "avformat.h"
+#include "internal.h"
+#include "nal.h"
+#include "vpcc.h"
+
+static const struct codec_string {
+ enum AVCodecID id;
+ char str[8];
+} codecs[] = {
+ { AV_CODEC_ID_VP8, "vp8" },
+ { AV_CODEC_ID_VP9, "vp9" },
+ { AV_CODEC_ID_VORBIS, "vorbis" },
+ { AV_CODEC_ID_OPUS, "opus" },
+ { AV_CODEC_ID_FLAC, "flac" },
+ { AV_CODEC_ID_NONE }
+};
+
+static void set_vp9_codec_str(void *logctx, const AVCodecParameters *par,
+ const AVRational *frame_rate, char *str, int
size) {
+ VPCC vpcc;
+ int ret = ff_isom_get_vpcc_features(logctx, par, NULL, 0, frame_rate,
&vpcc);
+ if (ret == 0) {
+ snprintf(str, size, "vp09.%02d.%02d.%02d",
+ vpcc.profile, vpcc.level, vpcc.bitdepth);
+ } else {
+ // Default to just vp9 in case of error while finding out profile or
level
+ av_log(logctx, AV_LOG_WARNING, "Could not find VP9 profile and/or
level\n");
+ av_strlcpy(str, "vp9", size);
+ }
+}
+
+int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
+ const AVRational *frame_rate, char *str, size_t size)
+{
+ int i;
+
+ if (size < 5)
+ return AVERROR(EINVAL);
+
+ str[0] = '\0';
+
+ // common Webm codecs are not part of RFC 6381
+ for (i = 0; codecs[i].id != AV_CODEC_ID_NONE; i++)
+ if (codecs[i].id == par->codec_id) {
+ if (codecs[i].id == AV_CODEC_ID_VP9) {
+ set_vp9_codec_str(logctx, par, frame_rate, str, size);
+ } else {
+ av_strlcpy(str, codecs[i].str, size);
+ }
+ return 0;
+ }
+
+ if (par->codec_id == AV_CODEC_ID_H264) {
+ // RFC 6381
+ uint8_t *data = par->extradata;
+ if (data) {
+ const uint8_t *p;
+
+ if (AV_RB32(data) == 0x01 && (data[4] & 0x1F) == 7)
+ p = &data[5];
+ else if (AV_RB24(data) == 0x01 && (data[3] & 0x1F) == 7)
+ p = &data[4];
+ else if (data[0] == 0x01) /* avcC */
+ p = &data[1];
+ else
+ return AVERROR(EINVAL);
+ snprintf(str, size,
+ "avc1.%02x%02x%02x", p[0], p[1], p[2]);
+ } else {
+ return AVERROR(EINVAL);
+ }
+ } else if (par->codec_id == AV_CODEC_ID_HEVC) {
+ // 3GPP TS 26.244
+ 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 AVERROR(EINVAL);
+ 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 (par->codec_tag == MKTAG('h','v','c','1') &&
+ profile != AV_PROFILE_UNKNOWN &&
+ profile_compatibility != AV_PROFILE_UNKNOWN &&
+ tier != 0 &&
+ level != AV_LEVEL_UNKNOWN &&
+ constraints[0] != '\0') {
+ snprintf(str, size, "%s.%d.%x.%c%d.%s",
av_fourcc2str(par->codec_tag), profile, profile_compatibility, tier, level,
constraints);
+ } else
+ return AVERROR(EINVAL);
+ } else if (par->codec_id == AV_CODEC_ID_AV1) {
+ // https://aomediacodec.github.io/av1-isobmff/#codecsparam
+ AV1SequenceParameters seq;
+ int err;
+ if (!par->extradata_size)
+ return AVERROR(EINVAL);
+ if ((err = ff_av1_parse_seq_header(&seq, par->extradata,
par->extradata_size)) < 0)
+ return err;
+
+ snprintf(str, size, "av01.%01u.%02u%s.%02u",
+ seq.profile, seq.level, seq.tier ? "H" : "M",
seq.bitdepth);
+ if (seq.color_description_present_flag)
+ av_strlcatf(str, size, ".%01u.%01u%01u%01u.%02u.%02u.%02u.%01u",
+ seq.monochrome,
+ seq.chroma_subsampling_x, seq.chroma_subsampling_y,
seq.chroma_sample_position,
+ seq.color_primaries, seq.transfer_characteristics,
seq.matrix_coefficients,
+ seq.color_range);
+ } else if (par->codec_id == AV_CODEC_ID_MPEG4) {
+ // RFC 6381
+ snprintf(str, size, "mp4v.20");
+ // Unimplemented, should output ProfileLevelIndication as a decimal
number
+ av_log(logctx, AV_LOG_WARNING, "Incomplete RFC 6381 codec string for
mp4v\n");
+ } else if (par->codec_id == AV_CODEC_ID_MP2) {
+ snprintf(str, size, "mp4a.40.33");
+ } else if (par->codec_id == AV_CODEC_ID_MP3) {
+ snprintf(str, size, "mp4a.40.34");
+ } else if (par->codec_id == AV_CODEC_ID_AAC) {
+ // RFC 6381
+ int aot = 2;
+ if (par->extradata_size >= 2) {
+ aot = par->extradata[0] >> 3;
+ if (aot == 31)
+ aot = ((AV_RB16(par->extradata) >> 5) & 0x3f) + 32;
+ } else if (par->profile != AV_PROFILE_UNKNOWN)
+ aot = par->profile + 1;
+ snprintf(str, size, "mp4a.40.%d", aot);
+ } else if (par->codec_id == AV_CODEC_ID_AC3) {
+ snprintf(str, size, "ac-3");
+ } else if (par->codec_id == AV_CODEC_ID_EAC3) {
+ snprintf(str, size, "ec-3");
+ } else {
+ return AVERROR(EINVAL);
+ }
+ return 0;
+}
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index af92e38bbd..636e770450 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -42,8 +42,6 @@
#include "libavcodec/avcodec.h"
-#include "av1.h"
-#include "avc.h"
#include "avformat.h"
#include "avio_internal.h"
#include "hlsplaylist.h"
@@ -51,11 +49,9 @@
#include "http.h"
#endif
#include "internal.h"
-#include "isom.h"
#include "mux.h"
#include "os_support.h"
#include "url.h"
-#include "vpcc.h"
#include "dash.h"
typedef enum {
@@ -206,18 +202,6 @@ typedef struct DASHContext {
int64_t update_period;
} DASHContext;
-static const struct codec_string {
- enum AVCodecID id;
- const char str[8];
-} codecs[] = {
- { AV_CODEC_ID_VP8, "vp8" },
- { AV_CODEC_ID_VP9, "vp9" },
- { AV_CODEC_ID_VORBIS, "vorbis" },
- { AV_CODEC_ID_OPUS, "opus" },
- { AV_CODEC_ID_FLAC, "flac" },
- { AV_CODEC_ID_NONE }
-};
-
static int dashenc_io_open(AVFormatContext *s, AVIOContext **pb, char
*filename,
AVDictionary **options) {
DASHContext *c = s->priv_data;
@@ -327,117 +311,6 @@ static int init_segment_types(AVFormatContext *s)
return 0;
}
-static void set_vp9_codec_str(AVFormatContext *s, AVCodecParameters *par,
- AVRational *frame_rate, char *str, int size) {
- VPCC vpcc;
- int ret = ff_isom_get_vpcc_features(s, par, NULL, 0, frame_rate, &vpcc);
- if (ret == 0) {
- av_strlcatf(str, size, "vp09.%02d.%02d.%02d",
- vpcc.profile, vpcc.level, vpcc.bitdepth);
- } else {
- // Default to just vp9 in case of error while finding out profile or
level
- av_log(s, AV_LOG_WARNING, "Could not find VP9 profile and/or level\n");
- av_strlcpy(str, "vp9", size);
- }
- return;
-}
-
-static void set_codec_str(AVFormatContext *s, AVCodecParameters *par,
- AVRational *frame_rate, char *str, int size)
-{
- const AVCodecTag *tags[2] = { NULL, NULL };
- uint32_t tag;
- int i;
-
- // common Webm codecs are not part of RFC 6381
- for (i = 0; codecs[i].id != AV_CODEC_ID_NONE; i++)
- if (codecs[i].id == par->codec_id) {
- if (codecs[i].id == AV_CODEC_ID_VP9) {
- set_vp9_codec_str(s, par, frame_rate, str, size);
- } else {
- av_strlcpy(str, codecs[i].str, size);
- }
- return;
- }
-
- // for codecs part of RFC 6381
- if (par->codec_type == AVMEDIA_TYPE_VIDEO)
- tags[0] = ff_codec_movvideo_tags;
- else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
- tags[0] = ff_codec_movaudio_tags;
- else
- return;
-
- tag = par->codec_tag;
- if (!tag)
- tag = av_codec_get_tag(tags, par->codec_id);
- if (!tag)
- return;
- if (size < 5)
- return;
-
- AV_WL32(str, tag);
- str[4] = '\0';
- if (!strcmp(str, "mp4a") || !strcmp(str, "mp4v")) {
- uint32_t oti;
- tags[0] = ff_mp4_obj_type;
- oti = av_codec_get_tag(tags, par->codec_id);
- if (oti)
- av_strlcatf(str, size, ".%02"PRIx32, oti);
- else
- return;
-
- if (tag == MKTAG('m', 'p', '4', 'a')) {
- if (par->extradata_size >= 2) {
- int aot = par->extradata[0] >> 3;
- if (aot == 31)
- aot = ((AV_RB16(par->extradata) >> 5) & 0x3f) + 32;
- av_strlcatf(str, size, ".%d", aot);
- }
- } else if (tag == MKTAG('m', 'p', '4', 'v')) {
- // Unimplemented, should output ProfileLevelIndication as a
decimal number
- av_log(s, AV_LOG_WARNING, "Incomplete RFC 6381 codec string for
mp4v\n");
- }
- } else if (!strcmp(str, "avc1")) {
- uint8_t *tmpbuf = NULL;
- uint8_t *extradata = par->extradata;
- int extradata_size = par->extradata_size;
- if (!extradata_size)
- return;
- if (extradata[0] != 1) {
- AVIOContext *pb;
- if (avio_open_dyn_buf(&pb) < 0)
- return;
- if (ff_isom_write_avcc(pb, extradata, extradata_size) < 0) {
- ffio_free_dyn_buf(&pb);
- return;
- }
- extradata_size = avio_close_dyn_buf(pb, &extradata);
- tmpbuf = extradata;
- }
-
- if (extradata_size >= 4)
- av_strlcatf(str, size, ".%02x%02x%02x",
- extradata[1], extradata[2], extradata[3]);
- av_free(tmpbuf);
- } else if (!strcmp(str, "av01")) {
- AV1SequenceParameters seq;
- if (!par->extradata_size)
- return;
- if (ff_av1_parse_seq_header(&seq, par->extradata, par->extradata_size)
< 0)
- return;
-
- av_strlcatf(str, size, ".%01u.%02u%s.%02u",
- seq.profile, seq.level, seq.tier ? "H" : "M",
seq.bitdepth);
- if (seq.color_description_present_flag)
- av_strlcatf(str, size, ".%01u.%01u%01u%01u.%02u.%02u.%02u.%01u",
- seq.monochrome,
- seq.chroma_subsampling_x, seq.chroma_subsampling_y,
seq.chroma_sample_position,
- seq.color_primaries, seq.transfer_characteristics,
seq.matrix_coefficients,
- seq.color_range);
- }
-}
-
static int flush_dynbuf(DASHContext *c, OutputStream *os, int *range_length)
{
uint8_t *buffer;
@@ -1701,8 +1574,8 @@ static int dash_init(AVFormatContext *s)
c->has_video = 1;
}
- set_codec_str(s, st->codecpar, &st->avg_frame_rate, os->codec_str,
- sizeof(os->codec_str));
+ ff_make_codec_str(s, st->codecpar, &st->avg_frame_rate, os->codec_str,
+ sizeof(os->codec_str));
os->first_pts = AV_NOPTS_VALUE;
os->max_pts = AV_NOPTS_VALUE;
os->last_dts = AV_NOPTS_VALUE;
@@ -1838,7 +1711,7 @@ static int update_stream_extradata(AVFormatContext *s,
OutputStream *os,
memcpy(par->extradata, extradata, extradata_size);
- set_codec_str(s, par, frame_rate, os->codec_str, sizeof(os->codec_str));
+ ff_make_codec_str(s, par, frame_rate, os->codec_str,
sizeof(os->codec_str));
return 0;
}
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d3db83093c..8e36887e06 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -44,13 +44,11 @@
#include "avformat.h"
#include "avio_internal.h"
-#include "avc.h"
#if CONFIG_HTTP_PROTOCOL
#include "http.h"
#endif
#include "hlsplaylist.h"
#include "internal.h"
-#include "nal.h"
#include "mux.h"
#include "os_support.h"
#include "url.h"
@@ -358,118 +356,10 @@ static void write_codec_attr(AVStream *st, VariantStream
*vs)
if (vs->attr_status == CODEC_ATTRIBUTE_WILL_NOT_BE_WRITTEN)
return;
- if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
- uint8_t *data = st->codecpar->extradata;
- if (data) {
- const uint8_t *p;
-
- if (AV_RB32(data) == 0x01 && (data[4] & 0x1F) == 7)
- p = &data[5];
- else if (AV_RB24(data) == 0x01 && (data[3] & 0x1F) == 7)
- p = &data[4];
- else if (data[0] == 0x01) /* avcC */
- p = &data[1];
- else
- goto fail;
- snprintf(attr, sizeof(attr),
- "avc1.%02x%02x%02x", p[0], p[1], p[2]);
- } else {
- goto fail;
- }
- } 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[8] = "";
-
- if (st->codecpar->profile != AV_PROFILE_UNKNOWN)
- profile = st->codecpar->profile;
- if (st->codecpar->level != AV_LEVEL_UNKNOWN)
- level = st->codecpar->level;
-
- /* check the boundary of data which from current position is small
than extradata_size */
- while (data && (data - st->codecpar->extradata + 19) <
st->codecpar->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 = st->codecpar->extradata_size - (data -
st->codecpar->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 (st->codecpar->codec_tag == MKTAG('h','v','c','1') &&
- profile != AV_PROFILE_UNKNOWN &&
- profile_compatibility != AV_PROFILE_UNKNOWN &&
- tier != 0 &&
- level != AV_LEVEL_UNKNOWN &&
- 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) {
- snprintf(attr, sizeof(attr), "mp4a.40.33");
- } else if (st->codecpar->codec_id == AV_CODEC_ID_MP3) {
- snprintf(attr, sizeof(attr), "mp4a.40.34");
- } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
- if (st->codecpar->profile != AV_PROFILE_UNKNOWN)
- snprintf(attr, sizeof(attr), "mp4a.40.%d",
st->codecpar->profile+1);
- else
- // This is for backward compatibility with the previous
implementation.
- snprintf(attr, sizeof(attr), "mp4a.40.2");
- } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
- snprintf(attr, sizeof(attr), "ac-3");
- } else if (st->codecpar->codec_id == AV_CODEC_ID_EAC3) {
- snprintf(attr, sizeof(attr), "ec-3");
- } else {
+ if (ff_make_codec_str(vs->avf, st->codecpar, &st->avg_frame_rate,
+ attr, sizeof(attr)) < 0)
goto fail;
- }
+
// Don't write the same attribute multiple times
if (!av_stristr(vs->codec_attr, attr)) {
snprintf(vs->codec_attr + codec_strlen,
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 1a50ba07d3..54b2ad6c79 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -661,4 +661,18 @@ int ff_dict_set_timestamp(AVDictionary **dict, const char
*key, int64_t timestam
*/
int ff_parse_opts_from_query_string(void *obj, const char *str, int
allow_unkown);
+/**
+ * Make a RFC 4281/6381 like string describing a codec.
+ *
+ * @param logctx a context for potential log messages
+ * @param par pointer to an AVCodecParameters struct describing the codec
+ * @param frame_rate an optional pointer to AVRational for the frame rate,
+ * for deciding the right profile for video codecs
+ * @param str the output string buffer
+ * @param size the size of the string pointed to by str
+ * @return <0 on error
+ */
+int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
+ const AVRational *frame_rate, char *str, size_t size);
+
#endif /* AVFORMAT_INTERNAL_H */
commit ee22107c67463ee8a3bec417a9318fa4c2653b9e
Author: Martin Storsjö <[email protected]>
AuthorDate: Mon Oct 27 13:06:26 2025 +0200
Commit: Martin Storsjö <[email protected]>
CommitDate: Sat Nov 8 21:19:31 2025 +0000
avformat/vpcc: Make input pointers const
diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
index f97700f5e6..6601219e6a 100644
--- a/libavformat/vpcc.c
+++ b/libavformat/vpcc.c
@@ -72,7 +72,9 @@ static int get_vpx_video_full_range_flag(enum AVColorRange
color_range)
}
// Find approximate VP9 level based on the Luma's Sample rate and Picture size.
-static int get_vp9_level(AVCodecParameters *par, AVRational *frame_rate) {
+static int get_vp9_level(const AVCodecParameters *par,
+ const AVRational *frame_rate)
+{
int picture_size = par->width * par->height;
int64_t sample_rate;
@@ -150,9 +152,9 @@ static void parse_bitstream(GetBitContext *gb, int
*profile, int *bit_depth) {
*bit_depth = *profile <= 1 ? 8 : 10 + get_bits1(gb) * 2;
}
-int ff_isom_get_vpcc_features(void *logctx, AVCodecParameters *par,
+int ff_isom_get_vpcc_features(void *logctx, const AVCodecParameters *par,
const uint8_t *data, int len,
- AVRational *frame_rate, VPCC *vpcc)
+ const AVRational *frame_rate, VPCC *vpcc)
{
int profile = par->profile;
int level = par->level == AV_LEVEL_UNKNOWN ?
@@ -199,7 +201,7 @@ int ff_isom_get_vpcc_features(void *logctx,
AVCodecParameters *par,
int ff_isom_write_vpcc(void *logctx, AVIOContext *pb,
const uint8_t *data, int len,
- AVCodecParameters *par)
+ const AVCodecParameters *par)
{
VPCC vpcc;
int ret;
diff --git a/libavformat/vpcc.h b/libavformat/vpcc.h
index 2301caf219..d7f81c439f 100644
--- a/libavformat/vpcc.h
+++ b/libavformat/vpcc.h
@@ -53,10 +53,10 @@ typedef struct VPCC {
*/
int ff_isom_write_vpcc(void *logctx, AVIOContext *pb,
const uint8_t *data, int len,
- AVCodecParameters *par);
+ const AVCodecParameters *par);
-int ff_isom_get_vpcc_features(void *logctx, AVCodecParameters *par,
+int ff_isom_get_vpcc_features(void *logctx, const AVCodecParameters *par,
const uint8_t *data, int len,
- AVRational *frame_rate, VPCC *vpcc);
+ const AVRational *frame_rate, VPCC *vpcc);
#endif /* AVFORMAT_VPCC_H */
commit d015382f4a80d533b0809f0267cc1be95f61a7bb
Author: Martin Storsjö <[email protected]>
AuthorDate: Thu Oct 23 13:35:12 2025 +0300
Commit: Martin Storsjö <[email protected]>
CommitDate: Sat Nov 8 21:19:31 2025 +0000
avformat/vpcc: Generalize the AVFormatContext parameter to void*
This parameter is only used as a logging context; don't require
a full AVFormatContext here.
diff --git a/libavformat/vpcc.c b/libavformat/vpcc.c
index a5977916bf..f97700f5e6 100644
--- a/libavformat/vpcc.c
+++ b/libavformat/vpcc.c
@@ -35,7 +35,7 @@ enum VPX_CHROMA_SUBSAMPLING
VPX_SUBSAMPLING_444 = 3,
};
-static int get_vpx_chroma_subsampling(AVFormatContext *s,
+static int get_vpx_chroma_subsampling(void *logctx,
enum AVPixelFormat pixel_format,
enum AVChromaLocation chroma_location)
{
@@ -51,15 +51,15 @@ static int get_vpx_chroma_subsampling(AVFormatContext *s,
return VPX_SUBSAMPLING_444;
}
}
- av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n", pixel_format);
+ av_log(logctx, AV_LOG_ERROR, "Unsupported pixel format (%d)\n",
pixel_format);
return -1;
}
-static int get_bit_depth(AVFormatContext *s, enum AVPixelFormat pixel_format)
+static int get_bit_depth(void *logctx, enum AVPixelFormat pixel_format)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pixel_format);
if (desc == NULL) {
- av_log(s, AV_LOG_ERROR, "Unsupported pixel format (%d)\n",
+ av_log(logctx, AV_LOG_ERROR, "Unsupported pixel format (%d)\n",
pixel_format);
return -1;
}
@@ -150,16 +150,16 @@ static void parse_bitstream(GetBitContext *gb, int
*profile, int *bit_depth) {
*bit_depth = *profile <= 1 ? 8 : 10 + get_bits1(gb) * 2;
}
-int ff_isom_get_vpcc_features(AVFormatContext *s, AVCodecParameters *par,
+int ff_isom_get_vpcc_features(void *logctx, AVCodecParameters *par,
const uint8_t *data, int len,
AVRational *frame_rate, VPCC *vpcc)
{
int profile = par->profile;
int level = par->level == AV_LEVEL_UNKNOWN ?
get_vp9_level(par, frame_rate) : par->level;
- int bit_depth = get_bit_depth(s, par->format);
+ int bit_depth = get_bit_depth(logctx, par->format);
int vpx_chroma_subsampling =
- get_vpx_chroma_subsampling(s, par->format, par->chroma_location);
+ get_vpx_chroma_subsampling(logctx, par->format, par->chroma_location);
int vpx_video_full_range_flag =
get_vpx_video_full_range_flag(par->color_range);
@@ -186,7 +186,7 @@ int ff_isom_get_vpcc_features(AVFormatContext *s,
AVCodecParameters *par,
}
if (profile == AV_PROFILE_UNKNOWN || !bit_depth)
- av_log(s, AV_LOG_WARNING, "VP9 profile and/or bit depth not set or
could not be derived\n");
+ av_log(logctx, AV_LOG_WARNING, "VP9 profile and/or bit depth not set
or could not be derived\n");
vpcc->profile = profile;
vpcc->level = level;
@@ -197,14 +197,14 @@ int ff_isom_get_vpcc_features(AVFormatContext *s,
AVCodecParameters *par,
return 0;
}
-int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
+int ff_isom_write_vpcc(void *logctx, AVIOContext *pb,
const uint8_t *data, int len,
AVCodecParameters *par)
{
VPCC vpcc;
int ret;
- ret = ff_isom_get_vpcc_features(s, par, data, len, NULL, &vpcc);
+ ret = ff_isom_get_vpcc_features(logctx, par, data, len, NULL, &vpcc);
if (ret < 0)
return ret;
diff --git a/libavformat/vpcc.h b/libavformat/vpcc.h
index bad38c5615..2301caf219 100644
--- a/libavformat/vpcc.h
+++ b/libavformat/vpcc.h
@@ -30,7 +30,6 @@
#include "libavutil/rational.h"
#include "libavcodec/codec_par.h"
#include "avio.h"
-#include "avformat.h"
typedef struct VPCC {
int profile;
@@ -43,7 +42,7 @@ typedef struct VPCC {
/**
* Writes VP codec configuration to the provided AVIOContext.
*
- * @param s address of the AVFormatContext for the logging context.
+ * @param logctx opaque pointer for logging.
* @param pb address of the AVIOContext where the vpcC shall be written.
* @param data address of a data array which contains coded bitstream data from
* which codec information can be extracted. May be NULL.
@@ -52,11 +51,11 @@ typedef struct VPCC {
* @return >=0 in case of success, a negative value corresponding to an AVERROR
* code in case of failure
*/
-int ff_isom_write_vpcc(AVFormatContext *s, AVIOContext *pb,
+int ff_isom_write_vpcc(void *logctx, AVIOContext *pb,
const uint8_t *data, int len,
AVCodecParameters *par);
-int ff_isom_get_vpcc_features(AVFormatContext *s, AVCodecParameters *par,
+int ff_isom_get_vpcc_features(void *logctx, AVCodecParameters *par,
const uint8_t *data, int len,
AVRational *frame_rate, VPCC *vpcc);
-----------------------------------------------------------------------
Summary of changes:
libavformat/Makefile | 4 +-
libavformat/codecstring.c | 220 ++++++++++++++++++++++++++++++++++++++++++++++
libavformat/dashenc.c | 136 ++--------------------------
libavformat/hlsenc.c | 118 ++-----------------------
libavformat/internal.h | 14 +++
libavformat/vpcc.c | 28 +++---
libavformat/vpcc.h | 11 ++-
7 files changed, 267 insertions(+), 264 deletions(-)
create mode 100644 libavformat/codecstring.c
hooks/post-receive
--
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]