Commit 7304d10462 for ffmpeg
commit 7304d104624536c620b2fdb92788d7cb617f7f33
Author: James Almer <jamrial@gmail.com>
Date: Tue Sep 29 00:15:00 2026 -0300
avutil/opt: add a serialization flag to exclude options with specific flags
Useful for example for scenarios like wanting to serialize only options that
are not marked as deprecated.
Signed-off-by: James Almer <jamrial@gmail.com>
diff --git a/doc/APIchanges b/doc/APIchanges
index f6e68f5eac..01c9639022 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2026-06-23.
API changes, most recent first:
+2026-10-07 - xxxxxxxxxx - lavu 61.12.100 - opt.h
+ Add AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE.
+
2026-10-03 - xxxxxxxxxx - lavu 61.11.100 - pixfmt.h
Add AV_PIX_FMT_XYZP12LE, AV_PIX_FMT_XYZP12BE, and AV_PIX_FMT_XYZP12.
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 8c3678d1be..b02efb9ff9 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -2816,10 +2816,18 @@ static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt,
while (o = av_opt_next(obj, o)) {
if (o->type == AV_OPT_TYPE_CONST)
continue;
- if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
- continue;
- else if (((o->flags & opt_flags) != opt_flags))
- continue;
+ if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE)) {
+ if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT)) {
+ if (o->flags == opt_flags)
+ continue;
+ } else if ((o->flags & opt_flags) == opt_flags)
+ continue;
+ } else {
+ if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
+ continue;
+ else if (((o->flags & opt_flags) != opt_flags))
+ continue;
+ }
if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0)
continue;
if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 7ab2b7ad7d..e14ad3f2f9 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -1090,8 +1090,17 @@ int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_fla
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS 0x00000001 ///< Serialize options that are not set to default values only.
-#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT 0x00000002 ///< Serialize options that exactly match opt_flags only.
+/**
+ * Match only options with the exact @ref AVOption.flags flags
+ * in @ref opt_flags, for exclusion or inclusion in serialization.
+ */
+#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT 0x00000002
#define AV_OPT_SERIALIZE_SEARCH_CHILDREN 0x00000004 ///< Serialize options in possible children of the given object.
+/**
+ * Serialize options with @ref AVOption.flags flags not
+ * in @ref opt_flags.
+ */
+#define AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE 0x00000008
/**
* Serialize object's options.
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index 04d5526dcd..4c167e2e49 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -385,19 +385,19 @@ int main(void)
if (ret < 0)
printf("Error ret '%d'\n", ret);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
- ChildContext child_ctx = { 0 };
+ ChildContext child_ctx = { .child_num64 = 1, .child_unum = 1 };
printf("%s\n", buf);
av_free(buf);
child_ctx.class = &child_class;
test_ctx.child = &child_ctx;
- if (av_opt_serialize(&test_ctx, 0,
- AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN,
+ printf("Exclude flag EXPORT:\n");
+ if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_EXPORT,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
+ AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE,
&buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_free(buf);
}
- child_ctx.child_num64 = 1;
- child_ctx.child_unum = 1;
printf("Include flag EXPORT:\n");
if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_EXPORT,
AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN,
@@ -405,6 +405,14 @@ int main(void)
printf("%s\n", buf);
av_free(buf);
}
+ printf("Exclude flag 1:\n");
+ if (av_opt_serialize(&test_ctx, 1,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
+ AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE,
+ &buf, '=', ',') >= 0) {
+ printf("%s\n", buf);
+ av_free(buf);
+ }
printf("Include flag 1:\n");
if (av_opt_serialize(&test_ctx, 1,
AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN,
@@ -412,6 +420,14 @@ int main(void)
printf("%s\n", buf);
av_free(buf);
}
+ printf("Exclude exact match flag 1:\n");
+ if (av_opt_serialize(&test_ctx, 1,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
+ AV_OPT_SERIALIZE_OPT_FLAGS_EXACT|AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE,
+ &buf, '=', ',') >= 0) {
+ printf("%s\n", buf);
+ av_free(buf);
+ }
printf("Include exact match flag 1:\n");
if (av_opt_serialize(&test_ctx, 1,
AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
@@ -420,6 +436,14 @@ int main(void)
printf("%s\n", buf);
av_free(buf);
}
+ printf("Exclude exact match flag EXPORT|READONLY:\n");
+ if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
+ AV_OPT_SERIALIZE_OPT_FLAGS_EXACT|AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE,
+ &buf, '=', ',') >= 0) {
+ printf("%s\n", buf);
+ av_free(buf);
+ }
printf("Include exact match flag EXPORT|READONLY:\n");
if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY,
AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN|
diff --git a/libavutil/version.h b/libavutil/version.h
index edc3fa5832..72219abbb9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 61
-#define LIBAVUTIL_VERSION_MINOR 11
+#define LIBAVUTIL_VERSION_MINOR 12
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 86f809c433..d14245ee6a 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -191,13 +191,20 @@ Setting entry with key 'array_int' to value ''
Setting entry with key 'array_str' to value 'str0|str\|1|str\\2'
Setting entry with key 'array_dict' to value 'k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0'
num=0,unum=2147483648,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
+Exclude flag EXPORT:
child_num=0,flt=0.333333,dbl=0.333333
Include flag EXPORT:
child_num64=1,child_unum=1
+Exclude flag 1:
+child_unum=1
Include flag 1:
child_num64=1,child_num=0,flt=0.333333,dbl=0.333333
+Exclude exact match flag 1:
+child_num64=1,child_unum=1
Include exact match flag 1:
child_num=0,flt=0.333333,dbl=0.333333
+Exclude exact match flag EXPORT|READONLY:
+child_num64=1,child_num=0,flt=0.333333,dbl=0.333333
Include exact match flag EXPORT|READONLY:
child_unum=1