diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-03-19 19:28:56 +0100 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-03-21 15:14:28 +0100 |
commit | 8e0d3c03698b5917cb9163f035935ecc7a864ada (patch) | |
tree | acf62087913af479007018d3677a13452083e292 /libavfilter/vf_ass.c | |
parent | c9399538b7561a27743e6a6c8a5784aa8c3f5805 (diff) | |
download | ffmpeg-streaming-8e0d3c03698b5917cb9163f035935ecc7a864ada.zip ffmpeg-streaming-8e0d3c03698b5917cb9163f035935ecc7a864ada.tar.gz |
lavfi/ass: add dar option
Allow to specify the display aspect ratio adopted for rendering
subtitles.
Diffstat (limited to 'libavfilter/vf_ass.c')
-rw-r--r-- | libavfilter/vf_ass.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/libavfilter/vf_ass.c b/libavfilter/vf_ass.c index b63d0db..bf13287 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; } |