[FFmpeg-cvslog] vsrc_color: switch to an AVOptions-based system.
Anton Khirnov
git at videolan.org
Thu Apr 11 03:15:52 CEST 2013
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Feb 25 21:21:29 2013 +0100| [7bc1a883c9158bb6e383d86fc76bdf2541e9a9fe] | committer: Anton Khirnov
vsrc_color: switch to an AVOptions-based system.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7bc1a883c9158bb6e383d86fc76bdf2541e9a9fe
---
doc/filters.texi | 7 ++-----
libavfilter/vsrc_color.c | 38 +++++++++++++++++++++++++++-----------
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index dd70f74..191bf6c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2315,9 +2315,6 @@ square pixels (1:1 sample aspect ratio).
Provide an uniformly colored input.
It accepts the following parameters:
- at var{color}:@var{frame_size}:@var{frame_rate}
-
-Follows the description of the accepted parameters.
@table @option
@@ -2326,12 +2323,12 @@ 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
alpha specifier. The default value is "black".
- at item frame_size
+ at item size
Specify the size of the sourced video, it may be a string of the form
@var{width}x at var{height}, or the name of a size abbreviation. The
default value is "320x240".
- at item frame_rate
+ at item framerate
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
@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float
diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c
index 9d9aab3..793af81 100644
--- a/libavfilter/vsrc_color.c
+++ b/libavfilter/vsrc_color.c
@@ -36,10 +36,12 @@
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
+#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "drawutils.h"
typedef struct {
+ const AVClass *class;
int w, h;
uint8_t color[4];
AVRational time_base;
@@ -47,34 +49,31 @@ typedef struct {
int line_step[4];
int hsub, vsub; ///< chroma subsampling values
uint64_t pts;
+ char *color_str;
+ char *size_str;
+ char *framerate_str;
} ColorContext;
static av_cold int color_init(AVFilterContext *ctx, const char *args)
{
ColorContext *color = ctx->priv;
- char color_string[128] = "black";
- char frame_size [128] = "320x240";
- char frame_rate [128] = "25";
AVRational frame_rate_q;
int ret;
- if (args)
- 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);
+ if (av_parse_video_size(&color->w, &color->h, color->size_str) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", color->size_str);
return AVERROR(EINVAL);
}
- if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 ||
+ if (av_parse_video_rate(&frame_rate_q, color->framerate_str) < 0 ||
frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
- av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate);
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", color->framerate_str);
return AVERROR(EINVAL);
}
color->time_base.num = frame_rate_q.den;
color->time_base.den = frame_rate_q.num;
- if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0)
+ if ((ret = av_parse_color(color->color, color->color_str, -1, ctx)) < 0)
return ret;
return 0;
@@ -160,6 +159,22 @@ static int color_request_frame(AVFilterLink *link)
return ff_filter_frame(link, frame);
}
+#define OFFSET(x) offsetof(ColorContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption options[] = {
+ { "color", "Output video color", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, .flags = FLAGS },
+ { "size", "Output video size (wxh or an abbreviation)", OFFSET(size_str), AV_OPT_TYPE_STRING, { .str = "320x240" }, .flags = FLAGS },
+ { "framerate", "Output video framerate", OFFSET(framerate_str), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVClass color_class = {
+ .class_name = "color",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
static const AVFilterPad avfilter_vsrc_color_outputs[] = {
{
.name = "default",
@@ -174,6 +189,7 @@ AVFilter avfilter_vsrc_color = {
.name = "color",
.description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"),
+ .priv_class = &color_class,
.priv_size = sizeof(ColorContext),
.init = color_init,
.uninit = color_uninit,
More information about the ffmpeg-cvslog
mailing list