Commit dcaa4efc authored by Nicolas George's avatar Nicolas George

buffersrc: accept key=value arguments.

The current flat arguments syntax is not easily extensible
due to sws_param possibly containing commas.
This is also consistent with abuffersrc.
parent 283cc059
...@@ -3162,33 +3162,26 @@ Buffer video frames, and make them available to the filter chain. ...@@ -3162,33 +3162,26 @@ Buffer video frames, and make them available to the filter chain.
This source is mainly intended for a programmatic use, in particular This source is mainly intended for a programmatic use, in particular
through the interface defined in @file{libavfilter/vsrc_buffer.h}. through the interface defined in @file{libavfilter/vsrc_buffer.h}.
It accepts the following parameters: It accepts a list of options in the form of @var{key}=@var{value} pairs
@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}:@var{scale_params} separated by ":". A descroption of the accepted options follows.
All the parameters but @var{scale_params} need to be explicitly
defined.
Follows the list of the accepted parameters.
@table @option @table @option
@item width, height @item video_size
Specify the width and height of the buffered video frames. Specify the size (width and height) of the buffered video frames.
@item pix_fmt_string @item pix_fmt
A string representing the pixel format of the buffered video frames. A string representing the pixel format of the buffered video frames.
It may be a number corresponding to a pixel format, or a pixel format It may be a number corresponding to a pixel format, or a pixel format
name. name.
@item timebase_num, timebase_den @item time_base
Specify numerator and denomitor of the timebase assumed by the Specify the timebase assumed by the timestamps of the buffered frames.
timestamps of the buffered frames.
@item sample_aspect_ratio.num, sample_aspect_ratio.den @item pixel_aspect
Specify numerator and denominator of the sample aspect ratio assumed Specify the sample aspect ratio assumed by the video frames.
by the video frames.
@item scale_params @item sws_param
Specify the optional parameters to be used for the scale filter which Specify the optional parameters to be used for the scale filter which
is automatically inserted when an input change is detected in the is automatically inserted when an input change is detected in the
input size or format. input size or format.
...@@ -3196,7 +3189,7 @@ input size or format. ...@@ -3196,7 +3189,7 @@ input size or format.
For example: For example:
@example @example
buffer=320:240:yuv410p:1:24:1:1 buffer=size=320x240:pix_fmt=yuv410p:time_base=1/24:pixel_aspect=1/1
@end example @end example
will instruct the source to accept video frames with size 320x240 and will instruct the source to accept video frames with size 320x240 and
...@@ -3206,9 +3199,14 @@ Since the pixel format with name "yuv410p" corresponds to the number 6 ...@@ -3206,9 +3199,14 @@ Since the pixel format with name "yuv410p" corresponds to the number 6
(check the enum PixelFormat definition in @file{libavutil/pixfmt.h}), (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}),
this example corresponds to: this example corresponds to:
@example @example
buffer=320:240:6:1:24:1:1 buffer=size=320x240:pixfmt=6:time_base=1/24:pixel_aspect=1/1
@end example @end example
Alternatively, the options can be specified as a flat string, but this
syntax is deprecated:
@var{width}:@var{height}:@var{pix_fmt}:@var{time_base.num}:@var{time_base.den}:@var{pixel_aspect.num}:@var{pixel_aspect.den}[:@var{sws_param}]
@section cellauto @section cellauto
Create a pattern generated by an elementary cellular automaton. Create a pattern generated by an elementary cellular automaton.
......
...@@ -45,10 +45,10 @@ typedef struct { ...@@ -45,10 +45,10 @@ typedef struct {
unsigned nb_failed_requests; unsigned nb_failed_requests;
/* video only */ /* video only */
int h, w; int w, h;
enum PixelFormat pix_fmt; enum PixelFormat pix_fmt;
AVRational pixel_aspect; AVRational pixel_aspect;
char sws_param[256]; char *sws_param;
/* audio only */ /* audio only */
int sample_rate; int sample_rate;
...@@ -216,35 +216,81 @@ unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src) ...@@ -216,35 +216,81 @@ unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src)
return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests; return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests;
} }
#define OFFSET(x) offsetof(BufferSourceContext, x)
#define V AV_OPT_FLAG_VIDEO_PARAM
static const AVOption video_options[] = {
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { 0 }, 0, INT_MAX, V },
{ "video_size", NULL, OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, .flags = V },
{ "pix_fmt", NULL, OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, .flags = V },
{ "pixel_aspect", NULL, OFFSET(pixel_aspect), AV_OPT_TYPE_RATIONAL, { 0 }, 0, INT_MAX, V },
{ "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V },
{ NULL },
};
#undef V
static const AVClass vbuffer_class = {
.class_name = "vbuffer source",
.item_name = av_default_item_name,
.option = video_options,
.version = LIBAVUTIL_VERSION_INT,
.category = AV_CLASS_CATEGORY_FILTER,
};
static av_cold int init_video(AVFilterContext *ctx, const char *args, void *opaque) static av_cold int init_video(AVFilterContext *ctx, const char *args, void *opaque)
{ {
BufferSourceContext *c = ctx->priv; BufferSourceContext *c = ctx->priv;
char pix_fmt_str[128]; char pix_fmt_str[128], sws_param[256] = "", *colon, *equal;
int ret, n = 0; int ret, n = 0;
*c->sws_param = 0;
if (!args || c->class = &vbuffer_class;
(n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str,
if (!args) {
av_log(ctx, AV_LOG_ERROR, "Arguments required\n");
return AVERROR(EINVAL);
}
colon = strchr(args, ':');
equal = strchr(args, '=');
if (equal && (!colon || equal < colon)) {
av_opt_set_defaults(c);
ret = av_set_options_string(c, args, "=", ":");
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Error parsing options string: %s.\n", args);
goto fail;
}
} else {
if ((n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str,
&c->time_base.num, &c->time_base.den, &c->time_base.num, &c->time_base.den,
&c->pixel_aspect.num, &c->pixel_aspect.den, c->sws_param)) < 7) { &c->pixel_aspect.num, &c->pixel_aspect.den, sws_param)) < 7) {
av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args); av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args);
return AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail;
} }
if ((ret = ff_parse_pixel_format(&c->pix_fmt, pix_fmt_str, ctx)) < 0) if ((ret = ff_parse_pixel_format(&c->pix_fmt, pix_fmt_str, ctx)) < 0)
return ret; goto fail;
c->sws_param = av_strdup(sws_param);
if (!c->sws_param) {
ret = AVERROR(ENOMEM);
goto fail;
}
}
if (!(c->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*)))) if (!(c->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*)))) {
return AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail;
}
av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n", av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n",
c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
c->time_base.num, c->time_base.den, c->time_base.num, c->time_base.den,
c->pixel_aspect.num, c->pixel_aspect.den, c->sws_param); c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""));
return 0; return 0;
fail:
av_opt_free(c);
return ret;
} }
#define OFFSET(x) offsetof(BufferSourceContext, x)
#define A AV_OPT_FLAG_AUDIO_PARAM #define A AV_OPT_FLAG_AUDIO_PARAM
static const AVOption audio_options[] = { static const AVOption audio_options[] = {
{ "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { 0 }, 0, INT_MAX, A }, { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { 0 }, 0, INT_MAX, A },
...@@ -318,6 +364,7 @@ static av_cold void uninit(AVFilterContext *ctx) ...@@ -318,6 +364,7 @@ static av_cold void uninit(AVFilterContext *ctx)
} }
av_fifo_free(s->fifo); av_fifo_free(s->fifo);
s->fifo = NULL; s->fifo = NULL;
av_freep(&s->sws_param);
} }
static int query_formats(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment