Merge commit 'e67a87eac814c7805d18c983c43033a8a1bd62af'

* 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

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-04-10 13:52:53 +02:00
commit 2a2a643c90
4 changed files with 95 additions and 33 deletions

View File

@ -689,13 +689,13 @@ The filter accepts the following named parameters:
@table @option
@item sample_fmts
A comma-separated list of requested sample formats.
A '|'-separated list of requested sample formats.
@item sample_rates
A comma-separated list of requested sample rates.
A '|'-separated list of requested sample rates.
@item channel_layouts
A comma-separated list of requested channel layouts.
A '|'-separated list of requested channel layouts.
@end table
@ -703,7 +703,7 @@ If a parameter is omitted, all values are allowed.
For example to force the output to either unsigned 8-bit or signed 16-bit stereo:
@example
aformat='sample_fmts=u8,s16:channel_layouts=stereo'
aformat=sample_fmts=u8|s16:channel_layouts=stereo
@end example
@section amerge
@ -3173,8 +3173,14 @@ Convert the input video to one of the specified pixel formats.
Libavfilter will try to pick one that is supported for the input to
the next filter.
The filter accepts a list of pixel format names, separated by ":",
for example "yuv420p:monow:rgb24".
This filter accepts the following parameters:
@table @option
@item pix_fmts
A '|'-separated list of pixel format names, for example
"pix_fmts=yuv420p|monow|rgb24".
@end table
@subsection Examples
@ -3182,12 +3188,12 @@ for example "yuv420p:monow:rgb24".
@item
Convert the input video to the format @var{yuv420p}
@example
format=yuv420p
format=pix_fmts=yuv420p
@end example
Convert the input video to any of the formats in the list
@example
format=yuv420p:yuv444p:yuv410p
format=pix_fmts=yuv420p|yuv444p|yuv410p
@end example
@end itemize
@ -4072,8 +4078,14 @@ alpha component (if available). The default value in input is 0.
Force libavfilter not to use any of the specified pixel formats for the
input to the next filter.
The filter accepts a list of pixel format names, separated by ":",
for example "yuv420p:monow:rgb24".
This filter accepts the following parameters:
@table @option
@item pix_fmts
A '|'-separated list of pixel format names, for example
"pix_fmts=yuv420p|monow|rgb24".
@end table
@subsection Examples
@ -4082,13 +4094,13 @@ for example "yuv420p:monow:rgb24".
Force libavfilter to use a format different from @var{yuv420p} for the
input to the vflip filter:
@example
noformat=yuv420p,vflip
noformat=pix_fmts=yuv420p,vflip
@end example
@item
Convert the input video to any of the formats not contained in the list:
@example
noformat=yuv420p:yuv444p:yuv410p
noformat=yuv420p|yuv444p|yuv410p
@end example
@end itemize

View File

@ -59,17 +59,24 @@ AVFILTER_DEFINE_CLASS(aformat);
#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc) \
do { \
char *next, *cur = str; \
char *next, *cur = str, sep; \
\
if (str && strchr(str, ',')) { \
av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "\
"separate %s.\n", desc); \
sep = ','; \
} else \
sep = '|'; \
\
while (cur) { \
type fmt; \
next = strchr(cur, ','); \
next = strchr(cur, sep); \
if (next) \
*next++ = 0; \
\
if ((fmt = get_fmt(cur)) == none) { \
av_log(ctx, AV_LOG_ERROR, "Error parsing " desc ": %s.\n", cur);\
ret = AVERROR(EINVAL); \
goto fail; \
return AVERROR(EINVAL); \
} \
add_to_list(&list, fmt); \
\
@ -86,18 +93,6 @@ static int get_sample_rate(const char *samplerate)
static av_cold int init(AVFilterContext *ctx, const char *args)
{
AFormatContext *s = ctx->priv;
int ret;
if (!args) {
av_log(ctx, AV_LOG_ERROR, "No parameters supplied.\n");
return AVERROR(EINVAL);
}
s->class = &aformat_class;
av_opt_set_defaults(s);
if ((ret = av_set_options_string(s, args, "=", ":")) < 0)
return ret;
PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats,
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)
ff_add_channel_layout, av_get_channel_layout, 0,
"channel layout");
fail:
av_opt_free(s);
return ret;
return 0;
}
static int query_formats(AVFilterContext *ctx)
@ -148,6 +141,7 @@ AVFilter avfilter_af_aformat = {
.init = init,
.query_formats = query_formats,
.priv_size = sizeof(AFormatContext),
.priv_class = &aformat_class,
.inputs = avfilter_af_aformat_inputs,
.outputs = avfilter_af_aformat_outputs,

View File

@ -654,6 +654,9 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
AVDictionaryEntry *e;
int ret=0;
int anton_options =
!strcmp(filter->filter->name, "aformat") ||
!strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat") ||
!strcmp(filter->filter->name, "resample")
;
@ -675,6 +678,33 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
ret = av_dict_parse_string(&options, args, "=", ":", 0);
if (ret < 0)
goto fail;
#if FF_API_OLD_FILTER_OPTS
} else if (!strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat")) {
/* a hack for compatibility with the old syntax
* replace colons with |s */
char *copy = av_strdup(args);
char *p = copy;
if (!copy) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (strchr(copy, ':')) {
av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
"'|' to separate the list items.\n");
}
while ((p = strchr(p, ':')))
*p++ = '|';
ret = process_unnamed_options(filter, &options, copy);
av_freep(&copy);
if (ret < 0)
goto fail;
#endif
} else {
ret = process_unnamed_options(filter, &options, args);
if (ret < 0)

View File

@ -28,6 +28,8 @@
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "internal.h"
#include "formats.h"
@ -35,6 +37,8 @@
#include "video.h"
typedef struct {
const AVClass *class;
char *pix_fmts;
/**
* List of flags telling if a given image format has been listed
* as argument to the filter.
@ -53,8 +57,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
enum AVPixelFormat pix_fmt;
/* parse the list of formats */
for (cur = args; cur; cur = sep ? sep+1 : NULL) {
if (!(sep = strchr(cur, ':')))
for (cur = format->pix_fmts; cur; cur = sep ? sep + 1 : NULL) {
if (!(sep = strchr(cur, '|')))
pix_fmt_name_len = strlen(cur);
else
pix_fmt_name_len = sep - cur;
@ -90,6 +94,12 @@ static AVFilterFormats *make_format_list(FormatContext *format, int flag)
return formats;
}
#define OFFSET(x) offsetof(FormatContext, x)
static const AVOption options[] = {
{ "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM },
{ NULL },
};
#if CONFIG_FORMAT_FILTER
static int query_formats_format(AVFilterContext *ctx)
{
@ -97,6 +107,13 @@ static int query_formats_format(AVFilterContext *ctx)
return 0;
}
static const AVClass format_class = {
.class_name = "format",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
static const AVFilterPad avfilter_vf_format_inputs[] = {
{
.name = "default",
@ -123,6 +140,7 @@ AVFilter avfilter_vf_format = {
.query_formats = query_formats_format,
.priv_size = sizeof(FormatContext),
.priv_class = &format_class,
.inputs = avfilter_vf_format_inputs,
.outputs = avfilter_vf_format_outputs,
@ -136,6 +154,13 @@ static int query_formats_noformat(AVFilterContext *ctx)
return 0;
}
static const AVClass noformat_class = {
.class_name = "noformat",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
static const AVFilterPad avfilter_vf_noformat_inputs[] = {
{
.name = "default",
@ -162,6 +187,7 @@ AVFilter avfilter_vf_noformat = {
.query_formats = query_formats_noformat,
.priv_size = sizeof(FormatContext),
.priv_class = &noformat_class,
.inputs = avfilter_vf_noformat_inputs,
.outputs = avfilter_vf_noformat_outputs,