diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-06-05 12:33:35 +0200 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-06-09 08:42:50 +0200 |
commit | dcaa4efcee37f6a7be85345939cdffd1bee41753 (patch) | |
tree | 3b8216f0d6e7361b5a89c7a9cb1176885c1bb0dd | |
parent | 283cc059386781b6fb90b9e5496d8963c3e416af (diff) | |
download | ffmpeg-dcaa4efcee37f6a7be85345939cdffd1bee41753.tar.gz |
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.
-rw-r--r-- | doc/filters.texi | 36 | ||||
-rw-r--r-- | libavfilter/buffersrc.c | 73 |
2 files changed, 77 insertions, 32 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index 150bde3189..d6e0dc7759 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -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 through the interface defined in @file{libavfilter/vsrc_buffer.h}. -It accepts the following parameters: -@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} - -All the parameters but @var{scale_params} need to be explicitly -defined. - -Follows the list of the accepted parameters. +It accepts a list of options in the form of @var{key}=@var{value} pairs +separated by ":". A descroption of the accepted options follows. @table @option -@item width, height -Specify the width and height of the buffered video frames. +@item video_size +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. It may be a number corresponding to a pixel format, or a pixel format name. -@item timebase_num, timebase_den -Specify numerator and denomitor of the timebase assumed by the -timestamps of the buffered frames. +@item time_base +Specify the timebase assumed by the timestamps of the buffered frames. -@item sample_aspect_ratio.num, sample_aspect_ratio.den -Specify numerator and denominator of the sample aspect ratio assumed -by the video frames. +@item pixel_aspect +Specify the sample aspect ratio assumed by the video frames. -@item scale_params +@item sws_param Specify the optional parameters to be used for the scale filter which is automatically inserted when an input change is detected in the input size or format. @@ -3196,7 +3189,7 @@ input size or format. For 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 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 (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}), this example corresponds to: @example -buffer=320:240:6:1:24:1:1 +buffer=size=320x240:pixfmt=6:time_base=1/24:pixel_aspect=1/1 @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 Create a pattern generated by an elementary cellular automaton. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 7a392f64f1..cd6c1f0d7b 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -45,10 +45,10 @@ typedef struct { unsigned nb_failed_requests; /* video only */ - int h, w; + int w, h; enum PixelFormat pix_fmt; AVRational pixel_aspect; - char sws_param[256]; + char *sws_param; /* audio only */ int sample_rate; @@ -216,35 +216,81 @@ unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src) 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) { BufferSourceContext *c = ctx->priv; - char pix_fmt_str[128]; + char pix_fmt_str[128], sws_param[256] = "", *colon, *equal; int ret, n = 0; - *c->sws_param = 0; - if (!args || - (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str, + c->class = &vbuffer_class; + + 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->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); - return AVERROR(EINVAL); + ret = AVERROR(EINVAL); + goto fail; } 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*)))) - return AVERROR(ENOMEM); + if (!(c->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*)))) { + 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", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, 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; + +fail: + av_opt_free(c); + return ret; } -#define OFFSET(x) offsetof(BufferSourceContext, x) #define A AV_OPT_FLAG_AUDIO_PARAM static const AVOption audio_options[] = { { "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) } av_fifo_free(s->fifo); s->fifo = NULL; + av_freep(&s->sws_param); } static int query_formats(AVFilterContext *ctx) |