avformat: Add av_mime_codec_str public API

Add a public API for producing RFC 4281/6381 codecs trings for
MIME types.

This can be required for providing alternative video files to
a web browser, letting the browser pick the best file it supports.
Such strings also allow querying a browser whether it supports
a certain codec combination.

Finally, if implementing a DASH/HLS segmenter outside of libavformat,
one also has to generate such strings.

Generating such strings for H264/AAC is very simple, but for
more modern codecs, it can require a lot of nontrivial codec
specific parsing of extradata.

As libavformat already implements this, expose it for users as well.

The old, internal function ff_make_codec_str is kept and used by
the HLS and DASH muxers; the old function takes a logging context
which can be used for logging auxillary info about how the string
generation worked out.
This commit is contained in:
Martin Storsjö
2025-10-23 13:49:15 +03:00
parent 360fda56cd
commit c9b5e145b7
5 changed files with 34 additions and 6 deletions

View File

@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
2025-12-xx - xxxxxxxxxx - lavf 62.x.xxx - avformat.h
Add av_mime_codec_str
2025-12-xx - xxxxxxxxxx - lavu 60.20.100 - hwcontext_vulkan.h
Add av_vk_get_optional_instance_extensions().
Add av_vk_get_optional_device_extensions().

View File

@@ -7,9 +7,11 @@ HEADERS = avformat.h \
version_major.h \
OBJS = allformats.o \
av1.o \
avformat.o \
avio.o \
aviobuf.o \
codecstring.o \
demux.o \
demux_utils.o \
dump.o \
@@ -21,6 +23,7 @@ OBJS = allformats.o \
metadata.o \
mux.o \
mux_utils.o \
nal.o \
options.o \
os_support.o \
protocols.o \
@@ -31,12 +34,13 @@ OBJS = allformats.o \
urldecode.o \
utils.o \
version.o \
vpcc.o \
OBJS-$(HAVE_LIBC_MSVCRT) += file_open.o
# subsystems
OBJS-$(CONFIG_ISO_MEDIA) += isom.o
OBJS-$(CONFIG_ISO_WRITER) += av1.o avc.o hevc.o nal.o vvc.o vpcc.o
OBJS-$(CONFIG_ISO_WRITER) += avc.o hevc.o vvc.o
OBJS-$(CONFIG_IAMFDEC) += iamf_reader.o iamf_parse.o iamf.o
OBJS-$(CONFIG_IAMFENC) += iamf_writer.o iamf.o
OBJS-$(CONFIG_NETWORK) += network.o
@@ -179,7 +183,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 codecstring.o
OBJS-$(CONFIG_DASH_MUXER) += dash.o dashenc.o hlsplaylist.o
OBJS-$(CONFIG_DASH_DEMUXER) += dash.o dashdec.o
OBJS-$(CONFIG_DAUD_DEMUXER) += dauddec.o
OBJS-$(CONFIG_DAUD_MUXER) += daudenc.o
@@ -267,7 +271,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 codecstring.o
OBJS-$(CONFIG_HLS_MUXER) += hlsenc.o hlsplaylist.o
OBJS-$(CONFIG_HNM_DEMUXER) += hnm.o
OBJS-$(CONFIG_HXVS_DEMUXER) += hxvs.o
OBJS-$(CONFIG_IAMF_DEMUXER) += iamfdec.o
@@ -634,7 +638,7 @@ OBJS-$(CONFIG_WAV_DEMUXER) += wavdec.o pcm.o
OBJS-$(CONFIG_WAV_MUXER) += wavenc.o
OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o
OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \
av1.o avlanguage.o
avlanguage.o
OBJS-$(CONFIG_WEBM_DASH_MANIFEST_MUXER) += webmdashenc.o
OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER) += webpenc.o

View File

@@ -2890,6 +2890,21 @@ int av_match_ext(const char *filename, const char *extensions);
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id,
int std_compliance);
struct AVBPrint;
/**
* Make a RFC 4281/6381 like string describing a codec for MIME types.
*
* @param par pointer to an AVCodecParameters struct describing the codec
* @param frame_rate an AVRational for the frame rate, for deciding the
* right profile for video codecs. Pass an invalid
* AVRational (1/0) to indicate that it is unknown.
* @param str the output string buffer
* @param size the size of the string pointed to by str
* @return <0 on error
*/
int av_mime_codec_str(const AVCodecParameters *par,
AVRational frame_rate, struct AVBPrint *out);
/**
* @defgroup riff_fourcc RIFF FourCCs
* @{

View File

@@ -220,3 +220,9 @@ int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
}
return 0;
}
int av_mime_codec_str(const AVCodecParameters *par,
AVRational frame_rate, struct AVBPrint *out)
{
return ff_make_codec_str(NULL, par, &frame_rate, out);
}

View File

@@ -31,8 +31,8 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 6
#define LIBAVFORMAT_VERSION_MICRO 103
#define LIBAVFORMAT_VERSION_MINOR 7
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \