PR #24764 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24764 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24764.patch
Useful for example for scenarios like wanting to serialize only options that are not marked as deprecated. >From 36055ac6f16ed91edb0e692f79721beec3badc3f Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Tue, 29 Sep 2026 00:15:00 -0300 Subject: [PATCH 1/3] 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 <[email protected]> --- libavutil/opt.c | 16 ++++++++++++---- libavutil/opt.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 8c3678d1be..8bee51b240 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)) + 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..2a2772c2dc 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 serialization or exclusion. + */ +#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. -- 2.52.0 >From 43124c34e88e86b9a1498131a8ba61922eea9a79 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Tue, 29 Sep 2026 00:15:56 -0300 Subject: [PATCH 2/3] avutil/tests/opt: add more tests for av_opt_serialize flags Signed-off-by: James Almer <[email protected]> --- libavutil/tests/opt.c | 27 ++++++++++++++++++++++++--- tests/ref/fate/opt | 5 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index 8ab76c4690..d356207af9 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -136,7 +136,7 @@ typedef struct ChildContext { #define OFFSET(x) offsetof(ChildContext, x) static const AVOption child_options[]= { - {"child_num64", "set num 64bit", OFFSET(child_num64), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 100, 1 }, + {"child_num64", "set num 64bit", OFFSET(child_num64), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 100, 1 | AV_OPT_FLAG_DEPRECATED }, {"child_num", "set child_num", OFFSET(child_num), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 100, 1 }, { NULL }, }; @@ -383,17 +383,38 @@ 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 }; printf("%s\n", buf); av_free(buf); child_ctx.class = &child_class; test_ctx.child = &child_ctx; - if (av_opt_serialize(&test_ctx, 0, + if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_DEPRECATED, + 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); + } + if (av_opt_serialize(&test_ctx, AV_OPT_FLAG_DEPRECATED, AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN, &buf, '=', ',') >= 0) { printf("%s\n", buf); av_free(buf); } + if (av_opt_serialize(&test_ctx, 1, + 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); + } + if (av_opt_serialize(&test_ctx, 1, + AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN| + AV_OPT_SERIALIZE_OPT_FLAGS_EXACT, + &buf, '=', ',') >= 0) { + printf("%s\n", buf); + av_free(buf); + } av_opt_free(&child_ctx); test_ctx.child = NULL; } diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index 04e787f01d..4e26dfc9a4 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -192,6 +192,11 @@ 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 child_num=0,flt=0.333333,dbl=0.333333 +The "child_num64" option is deprecated: set num 64bit +child_num64=1 +The "child_num64" option is deprecated: set num 64bit +child_num64=1,array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0 +child_num=0,flt=0.333333,dbl=0.333333 Testing av_set_options_string() Setting options string '' -- 2.52.0 >From e6f1064cc5a70d95954e7ee08fecadf904e45700 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Tue, 29 Sep 2026 00:16:59 -0300 Subject: [PATCH 3/3] fftools/ffmpeg_mux_init: skip deprecated AVOptions when mapping stream groups Silences warnings about lcevc_index being deprecated when mapping an input LCEVC stream group. Signed-off-by: James Almer <[email protected]> --- fftools/ffmpeg_mux_init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index a01a6b756e..7065aaa41d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2472,7 +2472,10 @@ static int of_serialize_options(Muxer *mux, void *obj, AVBPrint *bp) char *ptr; int ret; - ret = av_opt_serialize(obj, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS | AV_OPT_SERIALIZE_SEARCH_CHILDREN, + ret = av_opt_serialize(obj, AV_OPT_FLAG_DEPRECATED, + AV_OPT_SERIALIZE_SKIP_DEFAULTS | + AV_OPT_SERIALIZE_SEARCH_CHILDREN | + AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE, &ptr, '=', ':'); if (ret < 0) { av_log(mux, AV_LOG_ERROR, "Failed to serialize group\n"); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
