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