Commit 9e754336 authored by Paul B Mahol's avatar Paul B Mahol

lavfi/color: use AVOptions

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent cabbd271
...@@ -3419,24 +3419,28 @@ cellauto=p='@@@@ @@ @@@@':s=100x400:full=0:rule=18 ...@@ -3419,24 +3419,28 @@ cellauto=p='@@@@ @@ @@@@':s=100x400:full=0:rule=18
Provide an uniformly colored input. Provide an uniformly colored input.
It accepts the following parameters: This source accepts list of options in the form of
@var{color}:@var{frame_size}:@var{frame_rate} @var{key}=@var{value} pairs separated by ":".
Alternatively, it accepts a string in the form
@var{color}:@var{size}:@var{rate}, but this syntax is
deprecated.
Follows the description of the accepted parameters. Follows the description of the accepted parameters.
@table @option @table @option
@item color @item color, c
Specify the color of the source. It can be the name of a color (case Specify the color of the source. It can be the name of a color (case
insensitive match) or a 0xRRGGBB[AA] sequence, possibly followed by an insensitive match) or a 0xRRGGBB[AA] sequence, possibly followed by an
alpha specifier. The default value is "black". alpha specifier. The default value is "black".
@item frame_size @item size, s
Specify the size of the sourced video, it may be a string of the form Specify the size of the sourced video, it may be a string of the form
@var{width}x@var{height}, or the name of a size abbreviation. The @var{width}x@var{height}, or the name of a size abbreviation. The
default value is "320x240". default value is "320x240".
@item frame_rate @item rate, r
Specify the frame rate of the sourced video, as the number of frames Specify the frame rate of the sourced video, as the number of frames
generated per second. It has to be a string in the format generated per second. It has to be a string in the format
@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float @var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
...@@ -3451,7 +3455,7 @@ frames per second, which will be overlayed over the source connected ...@@ -3451,7 +3455,7 @@ frames per second, which will be overlayed over the source connected
to the pad with identifier "in". to the pad with identifier "in".
@example @example
"color=red@@0.2:qcif:10 [color]; [in][color] overlay [out]" "color=c=red@@0.2:s=qcif:r=10 [color]; [in][color] overlay [out]"
@end example @end example
@section movie @section movie
......
...@@ -31,11 +31,15 @@ ...@@ -31,11 +31,15 @@
#include "libavutil/colorspace.h" #include "libavutil/colorspace.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h" #include "libavutil/parseutils.h"
#include "drawutils.h" #include "drawutils.h"
typedef struct { typedef struct {
const AVClass *class;
int w, h; int w, h;
char *rate_str;
char *color_str;
uint8_t color_rgba[4]; uint8_t color_rgba[4];
AVRational time_base; AVRational time_base;
uint64_t pts; uint64_t pts;
...@@ -43,6 +47,26 @@ typedef struct { ...@@ -43,6 +47,26 @@ typedef struct {
FFDrawColor color; FFDrawColor color;
} ColorContext; } ColorContext;
#define OFFSET(x) offsetof(ColorContext, x)
static const AVOption color_options[]= {
{ "size", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
{ "s", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
{ "rate", "set frame rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
{ "r", "set frame rate", OFFSET(rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
{ "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
{ "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
{ NULL },
};
static const AVClass color_class = {
.class_name = "color",
.item_name = av_default_item_name,
.option = color_options,
.version = LIBAVUTIL_VERSION_INT,
.category = AV_CLASS_CATEGORY_FILTER,
};
static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque) static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque)
{ {
ColorContext *color = ctx->priv; ColorContext *color = ctx->priv;
...@@ -50,28 +74,54 @@ static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaq ...@@ -50,28 +74,54 @@ static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaq
char frame_size [128] = "320x240"; char frame_size [128] = "320x240";
char frame_rate [128] = "25"; char frame_rate [128] = "25";
AVRational frame_rate_q; AVRational frame_rate_q;
int ret; char *colon = 0, *equal = 0;
int ret = 0;
if (args) color->class = &color_class;
sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) { if (args) {
av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size); colon = strrchr(args, ':');
return AVERROR(EINVAL); equal = strrchr(args, '=');
} }
if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 || if (!args || (equal && (!colon || equal < colon))) {
frame_rate_q.den <= 0 || frame_rate_q.num <= 0) { av_opt_set_defaults(color);
av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate); if ((ret = av_set_options_string(color, args, "=", ":")) < 0) {
return AVERROR(EINVAL); av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
goto end;
}
if (av_parse_video_rate(&frame_rate_q, color->rate_str) < 0 ||
frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", color->rate_str);
ret = AVERROR(EINVAL);
goto end;
}
if (av_parse_color(color->color_rgba, color->color_str, -1, ctx) < 0) {
ret = AVERROR(EINVAL);
goto end;
}
} else {
av_log(ctx, AV_LOG_WARNING, "Flat options syntax is deprecated, use key=value pairs.\n");
sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate);
if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
return AVERROR(EINVAL);
}
if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
return AVERROR(EINVAL);
}
if (av_parse_color(color->color_rgba, color_string, -1, ctx) < 0)
return AVERROR(EINVAL);
} }
color->time_base.num = frame_rate_q.den; color->time_base.num = frame_rate_q.den;
color->time_base.den = frame_rate_q.num; color->time_base.den = frame_rate_q.num;
if ((ret = av_parse_color(color->color_rgba, color_string, -1, ctx)) < 0) end:
return ret; av_opt_free(color);
return ret;
return 0;
} }
static int query_formats(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx)
...@@ -123,7 +173,7 @@ static int color_request_frame(AVFilterLink *link) ...@@ -123,7 +173,7 @@ static int color_request_frame(AVFilterLink *link)
AVFilter avfilter_vsrc_color = { AVFilter avfilter_vsrc_color = {
.name = "color", .name = "color",
.description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]."), .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
.priv_size = sizeof(ColorContext), .priv_size = sizeof(ColorContext),
.init = color_init, .init = color_init,
......
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