summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-03-19 19:28:56 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-03-21 15:14:28 +0100
commit8e0d3c03698b5917cb9163f035935ecc7a864ada (patch)
treeacf62087913af479007018d3677a13452083e292
parentc9399538b7561a27743e6a6c8a5784aa8c3f5805 (diff)
lavfi/ass: add dar option
Allow to specify the display aspect ratio adopted for rendering subtitles.
-rw-r--r--doc/filters.texi13
-rw-r--r--libavfilter/version.h2
-rw-r--r--libavfilter/vf_ass.c43
3 files changed, 55 insertions, 3 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 9aedb01bb2..2863f8cf2a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -753,7 +753,18 @@ using the libass library.
To enable compilation of this filter you need to configure FFmpeg with
@code{--enable-libass}.
-This filter accepts in input the name of the ass file to render.
+This filter accepts the syntax: @var{ass_filename}[:@var{options}],
+where @var{ass_filename} is the filename of the ASS file to read, and
+@var{options} is an optional sequence of @var{key}=@var{value} pairs,
+separated by ":".
+
+A description of the accepted options follows.
+
+@table @option
+@item dar
+Specifies the display aspect ratio adopted for rendering the
+subtitles. Default value is "1.0".
+@end table
For example, to render the file @file{sub.ass} on top of the input
video, use the command:
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 2a85b2c60a..fa24bbd9d2 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 65
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MICRO 102
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_ass.c b/libavfilter/vf_ass.c
index b63d0db5bb..bf13287b33 100644
--- a/libavfilter/vf_ass.c
+++ b/libavfilter/vf_ass.c
@@ -30,11 +30,14 @@
#include "libavutil/avstring.h"
#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "drawutils.h"
#include "avfilter.h"
typedef struct {
+ const AVClass *class;
ASS_Library *library;
ASS_Renderer *renderer;
ASS_Track *track;
@@ -42,8 +45,28 @@ typedef struct {
char *filename;
uint8_t rgba_map[4];
int pix_step[4]; ///< steps per pixel for each plane of the main output
+ char *dar_str;
+ AVRational dar;
} AssContext;
+#define OFFSET(x) offsetof(AssContext, x)
+
+static const AVOption ass_options[] = {
+ {"dar", "set subtitles display aspect ratio", OFFSET(dar_str), AV_OPT_TYPE_STRING, {.str = "1.0"}, CHAR_MIN, CHAR_MAX },
+ {NULL},
+};
+
+static const char *ass_get_name(void *ctx)
+{
+ return "ass";
+}
+
+static const AVClass ass_class = {
+ "AssContext",
+ ass_get_name,
+ ass_options
+};
+
/* libass supports a log level ranging from 0 to 7 */
int ass_libav_log_level_map[] = {
AV_LOG_QUIET, /* 0 */
@@ -67,6 +90,10 @@ 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, void *opaque)
{
AssContext *ass = ctx->priv;
+ int ret;
+
+ ass->class = &ass_class;
+ av_opt_set_defaults(ass);
if (args)
ass->filename = av_get_token(&args, ":");
@@ -75,6 +102,18 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
return AVERROR(EINVAL);
}
+ if (*args++ == ':' && (ret = av_set_options_string(ass, args, "=", ":")) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+ return ret;
+ }
+
+ if (av_parse_ratio(&ass->dar, ass->dar_str, 100, 0, ctx) < 0 ||
+ ass->dar.num < 0 || ass->dar.den <= 0) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Invalid string '%s' or value for display aspect ratio.\n", ass->dar_str);
+ return AVERROR(EINVAL);
+ }
+
ass->library = ass_library_init();
if (!ass->library) {
av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
@@ -98,6 +137,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
+ av_log(ctx, AV_LOG_INFO, "dar:%f\n", av_q2d(ass->dar));
return 0;
}
@@ -106,6 +146,7 @@ static av_cold void uninit(AVFilterContext *ctx)
AssContext *ass = ctx->priv;
av_freep(&ass->filename);
+ av_freep(&ass->dar_str);
if (ass->track)
ass_free_track(ass->track);
if (ass->renderer)
@@ -142,7 +183,7 @@ static int config_input(AVFilterLink *inlink)
ass->vsub = pix_desc->log2_chroma_h;
ass_set_frame_size (ass->renderer, inlink->w, inlink->h);
- ass_set_aspect_ratio(ass->renderer, 1.0, sar);
+ ass_set_aspect_ratio(ass->renderer, av_q2d(ass->dar), sar);
return 0;
}