Commit faa1cb50 authored by Stefano Sabatini's avatar Stefano Sabatini

lavfi/ass: extend syntax for ass filter

Make the filter accept named options for the first argument, and update
documentation accordingly.
parent 22c5cc23
...@@ -1230,26 +1230,33 @@ using the libass library. ...@@ -1230,26 +1230,33 @@ using the libass library.
To enable compilation of this filter you need to configure FFmpeg with To enable compilation of this filter you need to configure FFmpeg with
@code{--enable-libass}. @code{--enable-libass}.
This filter accepts the syntax: @var{ass_filename}[:@var{options}], This filter accepts the following named options, expressed as a
where @var{ass_filename} is the filename of the ASS file to read, and sequence of @var{key}=@var{value} pairs, separated by ":".
@var{options} is an optional sequence of @var{key}=@var{value} pairs,
separated by ":".
A description of the accepted options follows.
@table @option @table @option
@item filename, f
Set the filename of the ASS file to read. It must be specified.
@item original_size @item original_size
Specifies the size of the original video, the video for which the ASS file Specify the size of the original video, the video for which the ASS file
was composed. Due to a misdesign in ASS aspect ratio arithmetic, this is was composed. Due to a misdesign in ASS aspect ratio arithmetic, this is
necessary to correctly scale the fonts if the aspect ratio has been changed. necessary to correctly scale the fonts if the aspect ratio has been changed.
@end table @end table
If the first key is not specified, it is assumed that the first value
specifies the @option{filename}.
For example, to render the file @file{sub.ass} on top of the input For example, to render the file @file{sub.ass} on top of the input
video, use the command: video, use the command:
@example @example
ass=sub.ass ass=sub.ass
@end example @end example
which is equivalent to:
@example
ass=filename=sub.ass
@end example
@section bbox @section bbox
Compute the bounding box for the non-black pixels in the input frame Compute the bounding box for the non-black pixels in the input frame
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 19 #define LIBAVFILTER_VERSION_MINOR 19
#define LIBAVFILTER_VERSION_MICRO 102 #define LIBAVFILTER_VERSION_MICRO 103
#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, \
......
...@@ -54,6 +54,8 @@ typedef struct { ...@@ -54,6 +54,8 @@ typedef struct {
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption ass_options[] = { static const AVOption ass_options[] = {
{"filename", "set the filename of the ASS file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
{"f", "set the filename of the ASS file to read", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
{"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, {"original_size", "set the size of the original video (used to scale fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
{NULL}, {NULL},
}; };
...@@ -83,21 +85,20 @@ static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx) ...@@ -83,21 +85,20 @@ static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx)
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
AssContext *ass = ctx->priv; AssContext *ass = ctx->priv;
static const char *shorthand[] = { "filename", NULL };
int ret; int ret;
ass->class = &ass_class; ass->class = &ass_class;
av_opt_set_defaults(ass); av_opt_set_defaults(ass);
if (args) if ((ret = av_opt_set_from_string(ass, args, shorthand, "=", ":")) < 0)
ass->filename = av_get_token(&args, ":"); return ret;
if (!ass->filename || !*ass->filename) {
if (!ass->filename) {
av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if (*args++ == ':' && (ret = av_set_options_string(ass, args, "=", ":")) < 0)
return ret;
ass->library = ass_library_init(); ass->library = ass_library_init();
if (!ass->library) { if (!ass->library) {
av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n"); av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
...@@ -127,7 +128,7 @@ static av_cold void uninit(AVFilterContext *ctx) ...@@ -127,7 +128,7 @@ static av_cold void uninit(AVFilterContext *ctx)
{ {
AssContext *ass = ctx->priv; AssContext *ass = ctx->priv;
av_freep(&ass->filename); av_opt_free(ass);
if (ass->track) if (ass->track)
ass_free_track(ass->track); ass_free_track(ass->track);
if (ass->renderer) if (ass->renderer)
......
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