1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavfi/pad: add support to named options

This commit is contained in:
Stefano Sabatini 2013-02-02 00:51:14 +01:00
parent c44281906a
commit 1897109c00
3 changed files with 84 additions and 52 deletions

View File

@ -3725,14 +3725,50 @@ testsrc=s=100x100, split=4 [in0][in1][in2][in3];
@section pad @section pad
Add paddings to the input image, and places the original input at the Add paddings to the input image, and place the original input at the
given coordinates @var{x}, @var{y}. given coordinates @var{x}, @var{y}.
It accepts the following parameters: The filter accepts parameters as a list of @var{key}=@var{value} pairs,
separated by ":".
If the key of the first options is omitted, the arguments are
interpreted according to the syntax
@var{width}:@var{height}:@var{x}:@var{y}:@var{color}. @var{width}:@var{height}:@var{x}:@var{y}:@var{color}.
The parameters @var{width}, @var{height}, @var{x}, and @var{y} are A description of the accepted options follows.
expressions containing the following constants:
@table @option
@item width, w
@item height, h
Specify an expression for the size of the output image with the
paddings added. If the value for @var{width} or @var{height} is 0, the
corresponding input size is used for the output.
The @var{width} expression can reference the value set by the
@var{height} expression, and vice versa.
The default value of @var{width} and @var{height} is 0.
@item x
@item y
Specify an expression for the offsets where to place the input image
in the padded area with respect to the top/left border of the output
image.
The @var{x} expression can reference the value set by the @var{y}
expression, and vice versa.
The default value of @var{x} and @var{y} is 0.
@item color
Specify the color of the padded area, it can be the name of a color
(case insensitive match) or a 0xRRGGBB[AA] sequence.
The default value of @var{color} is "black".
@end table
The value for the @var{width}, @var{height}, @var{x}, and @var{y}
options are expressions containing the following constants:
@table @option @table @option
@item in_w, in_h @item in_w, in_h
@ -3766,39 +3802,6 @@ horizontal and vertical chroma subsample values. For example for the
pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
@end table @end table
Follows the description of the accepted parameters.
@table @option
@item width, height
Specify the size of the output image with the paddings added. If the
value for @var{width} or @var{height} is 0, the corresponding input size
is used for the output.
The @var{width} expression can reference the value set by the
@var{height} expression, and vice versa.
The default value of @var{width} and @var{height} is 0.
@item x, y
Specify the offsets where to place the input image in the padded area
with respect to the top/left border of the output image.
The @var{x} expression can reference the value set by the @var{y}
expression, and vice versa.
The default value of @var{x} and @var{y} is 0.
@item color
Specify the color of the padded area, it can be the name of a color
(case insensitive match) or a 0xRRGGBB[AA] sequence.
The default value of @var{color} is "black".
@end table
@subsection Examples @subsection Examples
@itemize @itemize
@ -3810,6 +3813,11 @@ column 0, row 40:
pad=640:480:0:40:violet pad=640:480:0:40:violet
@end example @end example
The example above is equivalent to the following command:
@example
pad=width=640:height=480:x=0:y=40:color=violet
@end example
@item @item
Pad the input to get an output with dimensions increased by 3/2, Pad the input to get an output with dimensions increased by 3/2,
and put the input video at the center of the padded area: and put the input video at the center of the padded area:

View File

@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 35 #define LIBAVFILTER_VERSION_MINOR 35
#define LIBAVFILTER_VERSION_MICRO 100 #define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \ LIBAVFILTER_VERSION_MINOR, \

View File

@ -35,6 +35,7 @@
#include "libavutil/colorspace.h" #include "libavutil/colorspace.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h" #include "libavutil/parseutils.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "drawutils.h" #include "drawutils.h"
@ -76,40 +77,61 @@ static int query_formats(AVFilterContext *ctx)
} }
typedef struct { typedef struct {
const AVClass *class;
int w, h; ///< output dimensions, a value of 0 will result in the input size int w, h; ///< output dimensions, a value of 0 will result in the input size
int x, y; ///< offsets of the input area with respect to the padded area int x, y; ///< offsets of the input area with respect to the padded area
int in_w, in_h; ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues int in_w, in_h; ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues
char w_expr[256]; ///< width expression string char *w_expr; ///< width expression string
char h_expr[256]; ///< height expression string char *h_expr; ///< height expression string
char x_expr[256]; ///< width expression string char *x_expr; ///< width expression string
char y_expr[256]; ///< height expression string char *y_expr; ///< height expression string
char *color_str;
uint8_t rgba_color[4]; ///< color for the padding area uint8_t rgba_color[4]; ///< color for the padding area
FFDrawContext draw; FFDrawContext draw;
FFDrawColor color; FFDrawColor color;
} PadContext; } PadContext;
#define OFFSET(x) offsetof(PadContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption pad_options[] = {
{ "width", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "w", "set the pad area width expression", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "height", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "h", "set the pad area height expression", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "x", "set the x offset expression for the input image position", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "y", "set the y offset expression for the input image position", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "color", "set the color of the padded area border", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, .flags = FLAGS },
{NULL}
};
AVFILTER_DEFINE_CLASS(pad);
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
PadContext *pad = ctx->priv; PadContext *pad = ctx->priv;
char color_string[128] = "black"; static const char *shorthand[] = { "width", "height", "x", "y", "color", NULL };
int ret;
av_strlcpy(pad->w_expr, "iw", sizeof(pad->w_expr)); pad->class = &pad_class;
av_strlcpy(pad->h_expr, "ih", sizeof(pad->h_expr)); av_opt_set_defaults(pad);
av_strlcpy(pad->x_expr, "0" , sizeof(pad->w_expr));
av_strlcpy(pad->y_expr, "0" , sizeof(pad->h_expr));
if (args) if ((ret = av_opt_set_from_string(pad, args, shorthand, "=", ":")) < 0)
sscanf(args, "%255[^:]:%255[^:]:%255[^:]:%255[^:]:%127s", return ret;
pad->w_expr, pad->h_expr, pad->x_expr, pad->y_expr, color_string);
if (av_parse_color(pad->rgba_color, color_string, -1, ctx) < 0) if (av_parse_color(pad->rgba_color, pad->color_str, -1, ctx) < 0)
return AVERROR(EINVAL); return AVERROR(EINVAL);
return 0; return 0;
} }
static av_cold void uninit(AVFilterContext *ctx)
{
PadContext *pad = ctx->priv;
av_opt_free(pad);
}
static int config_input(AVFilterLink *inlink) static int config_input(AVFilterLink *inlink)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
@ -368,9 +390,11 @@ AVFilter avfilter_vf_pad = {
.priv_size = sizeof(PadContext), .priv_size = sizeof(PadContext),
.init = init, .init = init,
.uninit = uninit,
.query_formats = query_formats, .query_formats = query_formats,
.inputs = avfilter_vf_pad_inputs, .inputs = avfilter_vf_pad_inputs,
.outputs = avfilter_vf_pad_outputs, .outputs = avfilter_vf_pad_outputs,
.priv_class = &pad_class,
}; };