* commit 'e67a87eac814c7805d18c983c43033a8a1bd62af': vf_(no)format: switch to an AVOptions-based system. af_aformat: switch to an AVOptions-based system. Conflicts: doc/filters.texi libavfilter/af_aformat.c
Unified · Split
| @@ -689,13 +689,13 @@ The filter accepts the following named parameters: · 688 unmodified lines | ||
| 689 | 689 | @table @option |
| 690 | 690 | |
| 691 | 691 | @item sample_fmts |
| 692 | −A comma-separated list of requested sample formats. | |
| 692 | +A '|'-separated list of requested sample formats. | |
| 693 | 693 | |
| 694 | 694 | @item sample_rates |
| 695 | −A comma-separated list of requested sample rates. | |
| 695 | +A '|'-separated list of requested sample rates. | |
| 696 | 696 | |
| 697 | 697 | @item channel_layouts |
| 698 | −A comma-separated list of requested channel layouts. | |
| 698 | +A '|'-separated list of requested channel layouts. | |
| 699 | 699 | |
| 700 | 700 | @end table |
| 701 | 701 | |
| @@ -703,7 +703,7 @@ If a parameter is omitted, all values are allowed. · 1 unmodified line | ||
| 703 | 703 | |
| 704 | 704 | For example to force the output to either unsigned 8-bit or signed 16-bit stereo: |
| 705 | 705 | @example |
| 706 | −aformat='sample_fmts=u8,s16:channel_layouts=stereo' | |
| 706 | +aformat=sample_fmts=u8|s16:channel_layouts=stereo | |
| 707 | 707 | @end example |
| 708 | 708 | |
| 709 | 709 | @section amerge |
| @@ -3173,8 +3173,14 @@ Convert the input video to one of the specified pixel formats. · 2463 unmodified lines | ||
| 3173 | 3173 | Libavfilter will try to pick one that is supported for the input to |
| 3174 | 3174 | the next filter. |
| 3175 | 3175 | |
| 3176 | −The filter accepts a list of pixel format names, separated by ":", | |
| 3177 | −for example "yuv420p:monow:rgb24". | |
| 3176 | +This filter accepts the following parameters: | |
| 3177 | +@table @option | |
| 3178 | + | |
| 3179 | +@item pix_fmts | |
| 3180 | +A '|'-separated list of pixel format names, for example | |
| 3181 | +"pix_fmts=yuv420p|monow|rgb24". | |
| 3182 | + | |
| 3183 | +@end table | |
| 3178 | 3184 | |
| 3179 | 3185 | @subsection Examples |
| 3180 | 3186 | |
| @@ -3182,12 +3188,12 @@ for example "yuv420p:monow:rgb24". · 1 unmodified line | ||
| 3182 | 3188 | @item |
| 3183 | 3189 | Convert the input video to the format @var{yuv420p} |
| 3184 | 3190 | @example |
| 3185 | −format=yuv420p | |
| 3191 | +format=pix_fmts=yuv420p | |
| 3186 | 3192 | @end example |
| 3187 | 3193 | |
| 3188 | 3194 | Convert the input video to any of the formats in the list |
| 3189 | 3195 | @example |
| 3190 | −format=yuv420p:yuv444p:yuv410p | |
| 3196 | +format=pix_fmts=yuv420p|yuv444p|yuv410p | |
| 3191 | 3197 | @end example |
| 3192 | 3198 | @end itemize |
| 3193 | 3199 | |
| @@ -4072,8 +4078,14 @@ alpha component (if available). The default value in input is 0. · 878 unmodified lines | ||
| 4072 | 4078 | Force libavfilter not to use any of the specified pixel formats for the |
| 4073 | 4079 | input to the next filter. |
| 4074 | 4080 | |
| 4075 | −The filter accepts a list of pixel format names, separated by ":", | |
| 4076 | −for example "yuv420p:monow:rgb24". | |
| 4081 | +This filter accepts the following parameters: | |
| 4082 | +@table @option | |
| 4083 | + | |
| 4084 | +@item pix_fmts | |
| 4085 | +A '|'-separated list of pixel format names, for example | |
| 4086 | +"pix_fmts=yuv420p|monow|rgb24". | |
| 4087 | + | |
| 4088 | +@end table | |
| 4077 | 4089 | |
| 4078 | 4090 | @subsection Examples |
| 4079 | 4091 | |
| @@ -4082,13 +4094,13 @@ for example "yuv420p:monow:rgb24". · 2 unmodified lines | ||
| 4082 | 4094 | Force libavfilter to use a format different from @var{yuv420p} for the |
| 4083 | 4095 | input to the vflip filter: |
| 4084 | 4096 | @example |
| 4085 | −noformat=yuv420p,vflip | |
| 4097 | +noformat=pix_fmts=yuv420p,vflip | |
| 4086 | 4098 | @end example |
| 4087 | 4099 | |
| 4088 | 4100 | @item |
| 4089 | 4101 | Convert the input video to any of the formats not contained in the list: |
| 4090 | 4102 | @example |
| 4091 | −noformat=yuv420p:yuv444p:yuv410p | |
| 4103 | +noformat=yuv420p|yuv444p|yuv410p | |
| 4092 | 4104 | @end example |
| 4093 | 4105 | @end itemize |
| 4094 | 4106 | |
| @@ -59,17 +59,24 @@ AVFILTER_DEFINE_CLASS(aformat); · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | #define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc) \ |
| 61 | 61 | do { \ |
| 62 | − char *next, *cur = str; \ | |
| 62 | + char *next, *cur = str, sep; \ | |
| 63 | + \ | |
| 64 | + if (str && strchr(str, ',')) { \ | |
| 65 | + av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "\ | |
| 66 | + "separate %s.\n", desc); \ | |
| 67 | + sep = ','; \ | |
| 68 | + } else \ | |
| 69 | + sep = '|'; \ | |
| 70 | + \ | |
| 63 | 71 | while (cur) { \ |
| 64 | 72 | type fmt; \ |
| 65 | − next = strchr(cur, ','); \ | |
| 73 | + next = strchr(cur, sep); \ | |
| 66 | 74 | if (next) \ |
| 67 | 75 | *next++ = 0; \ |
| 68 | 76 | \ |
| 69 | 77 | if ((fmt = get_fmt(cur)) == none) { \ |
| 70 | 78 | av_log(ctx, AV_LOG_ERROR, "Error parsing " desc ": %s.\n", cur);\ |
| 71 | − ret = AVERROR(EINVAL); \ | |
| 72 | − goto fail; \ | |
| 79 | + return AVERROR(EINVAL); \ | |
| 73 | 80 | } \ |
| 74 | 81 | add_to_list(&list, fmt); \ |
| 75 | 82 | \ |
| @@ -86,18 +93,6 @@ static int get_sample_rate(const char *samplerate) · 10 unmodified lines | ||
| 86 | 93 | static av_cold int init(AVFilterContext *ctx, const char *args) |
| 87 | 94 | { |
| 88 | 95 | AFormatContext *s = ctx->priv; |
| 89 | − int ret; | |
| 90 | − | |
| 91 | − if (!args) { | |
| 92 | − av_log(ctx, AV_LOG_ERROR, "No parameters supplied.\n"); | |
| 93 | − return AVERROR(EINVAL); | |
| 94 | − } | |
| 95 | − | |
| 96 | − s->class = &aformat_class; | |
| 97 | − av_opt_set_defaults(s); | |
| 98 | − | |
| 99 | − if ((ret = av_set_options_string(s, args, "=", ":")) < 0) | |
| 100 | − return ret; | |
| 101 | 96 | |
| 102 | 97 | PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats, |
| 103 | 98 | ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format"); |
| @@ -107,9 +102,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 3 unmodified lines | ||
| 107 | 102 | ff_add_channel_layout, av_get_channel_layout, 0, |
| 108 | 103 | "channel layout"); |
| 109 | 104 | |
| 110 | −fail: | |
| 111 | − av_opt_free(s); | |
| 112 | − return ret; | |
| 105 | + return 0; | |
| 113 | 106 | } |
| 114 | 107 | |
| 115 | 108 | static int query_formats(AVFilterContext *ctx) |
| @@ -148,6 +141,7 @@ AVFilter avfilter_af_aformat = { · 32 unmodified lines | ||
| 148 | 141 | .init = init, |
| 149 | 142 | .query_formats = query_formats, |
| 150 | 143 | .priv_size = sizeof(AFormatContext), |
| 144 | + .priv_class = &aformat_class, | |
| 151 | 145 | |
| 152 | 146 | .inputs = avfilter_af_aformat_inputs, |
| 153 | 147 | .outputs = avfilter_af_aformat_outputs, |
| @@ -654,6 +654,9 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 653 unmodified lines | ||
| 654 | 654 | AVDictionaryEntry *e; |
| 655 | 655 | int ret=0; |
| 656 | 656 | int anton_options = |
| 657 | + !strcmp(filter->filter->name, "aformat") || | |
| 658 | + !strcmp(filter->filter->name, "format") || | |
| 659 | + !strcmp(filter->filter->name, "noformat") || | |
| 657 | 660 | !strcmp(filter->filter->name, "resample") |
| 658 | 661 | ; |
| 659 | 662 | |
| @@ -675,6 +678,33 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 15 unmodified lines | ||
| 675 | 678 | ret = av_dict_parse_string(&options, args, "=", ":", 0); |
| 676 | 679 | if (ret < 0) |
| 677 | 680 | goto fail; |
| 681 | +#if FF_API_OLD_FILTER_OPTS | |
| 682 | + } else if (!strcmp(filter->filter->name, "format") || | |
| 683 | + !strcmp(filter->filter->name, "noformat")) { | |
| 684 | + /* a hack for compatibility with the old syntax | |
| 685 | + * replace colons with |s */ | |
| 686 | + char *copy = av_strdup(args); | |
| 687 | + char *p = copy; | |
| 688 | + | |
| 689 | + if (!copy) { | |
| 690 | + ret = AVERROR(ENOMEM); | |
| 691 | + goto fail; | |
| 692 | + } | |
| 693 | + | |
| 694 | + if (strchr(copy, ':')) { | |
| 695 | + av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use " | |
| 696 | + "'|' to separate the list items.\n"); | |
| 697 | + } | |
| 698 | + | |
| 699 | + while ((p = strchr(p, ':'))) | |
| 700 | + *p++ = '|'; | |
| 701 | + | |
| 702 | + ret = process_unnamed_options(filter, &options, copy); | |
| 703 | + av_freep(©); | |
| 704 | + | |
| 705 | + if (ret < 0) | |
| 706 | + goto fail; | |
| 707 | +#endif | |
| 678 | 708 | } else { |
| 679 | 709 | ret = process_unnamed_options(filter, &options, args); |
| 680 | 710 | if (ret < 0) |
| @@ -28,6 +28,8 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "libavutil/internal.h" |
| 29 | 29 | #include "libavutil/mem.h" |
| 30 | 30 | #include "libavutil/pixdesc.h" |
| 31 | +#include "libavutil/opt.h" | |
| 32 | + | |
| 31 | 33 | #include "avfilter.h" |
| 32 | 34 | #include "internal.h" |
| 33 | 35 | #include "formats.h" |
| @@ -35,6 +37,8 @@ · 1 unmodified line | ||
| 35 | 37 | #include "video.h" |
| 36 | 38 | |
| 37 | 39 | typedef struct { |
| 40 | + const AVClass *class; | |
| 41 | + char *pix_fmts; | |
| 38 | 42 | /** |
| 39 | 43 | * List of flags telling if a given image format has been listed |
| 40 | 44 | * as argument to the filter. |
| @@ -53,8 +57,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 12 unmodified lines | ||
| 53 | 57 | enum AVPixelFormat pix_fmt; |
| 54 | 58 | |
| 55 | 59 | /* parse the list of formats */ |
| 56 | − for (cur = args; cur; cur = sep ? sep+1 : NULL) { | |
| 57 | − if (!(sep = strchr(cur, ':'))) | |
| 60 | + for (cur = format->pix_fmts; cur; cur = sep ? sep + 1 : NULL) { | |
| 61 | + if (!(sep = strchr(cur, '|'))) | |
| 58 | 62 | pix_fmt_name_len = strlen(cur); |
| 59 | 63 | else |
| 60 | 64 | pix_fmt_name_len = sep - cur; |
| @@ -90,6 +94,12 @@ static AVFilterFormats *make_format_list(FormatContext *format, int flag) · 29 unmodified lines | ||
| 90 | 94 | return formats; |
| 91 | 95 | } |
| 92 | 96 | |
| 97 | +#define OFFSET(x) offsetof(FormatContext, x) | |
| 98 | +static const AVOption options[] = { | |
| 99 | + { "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM }, | |
| 100 | + { NULL }, | |
| 101 | +}; | |
| 102 | + | |
| 93 | 103 | #if CONFIG_FORMAT_FILTER |
| 94 | 104 | static int query_formats_format(AVFilterContext *ctx) |
| 95 | 105 | { |
| @@ -97,6 +107,13 @@ static int query_formats_format(AVFilterContext *ctx) · 1 unmodified line | ||
| 97 | 107 | return 0; |
| 98 | 108 | } |
| 99 | 109 | |
| 110 | +static const AVClass format_class = { | |
| 111 | + .class_name = "format", | |
| 112 | + .item_name = av_default_item_name, | |
| 113 | + .option = options, | |
| 114 | + .version = LIBAVUTIL_VERSION_INT, | |
| 115 | +}; | |
| 116 | + | |
| 100 | 117 | static const AVFilterPad avfilter_vf_format_inputs[] = { |
| 101 | 118 | { |
| 102 | 119 | .name = "default", |
| @@ -123,6 +140,7 @@ AVFilter avfilter_vf_format = { · 20 unmodified lines | ||
| 123 | 140 | .query_formats = query_formats_format, |
| 124 | 141 | |
| 125 | 142 | .priv_size = sizeof(FormatContext), |
| 143 | + .priv_class = &format_class, | |
| 126 | 144 | |
| 127 | 145 | .inputs = avfilter_vf_format_inputs, |
| 128 | 146 | .outputs = avfilter_vf_format_outputs, |
| @@ -136,6 +154,13 @@ static int query_formats_noformat(AVFilterContext *ctx) · 7 unmodified lines | ||
| 136 | 154 | return 0; |
| 137 | 155 | } |
| 138 | 156 | |
| 157 | +static const AVClass noformat_class = { | |
| 158 | + .class_name = "noformat", | |
| 159 | + .item_name = av_default_item_name, | |
| 160 | + .option = options, | |
| 161 | + .version = LIBAVUTIL_VERSION_INT, | |
| 162 | +}; | |
| 163 | + | |
| 139 | 164 | static const AVFilterPad avfilter_vf_noformat_inputs[] = { |
| 140 | 165 | { |
| 141 | 166 | .name = "default", |
| @@ -162,6 +187,7 @@ AVFilter avfilter_vf_noformat = { · 20 unmodified lines | ||
| 162 | 187 | .query_formats = query_formats_noformat, |
| 163 | 188 | |
| 164 | 189 | .priv_size = sizeof(FormatContext), |
| 190 | + .priv_class = &noformat_class, | |
| 165 | 191 | |
| 166 | 192 | .inputs = avfilter_vf_noformat_inputs, |
| 167 | 193 | .outputs = avfilter_vf_noformat_outputs, |