Message ID | 20200330105233.12878-2-lance.lmwang@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v1,1/2] avfilter/vf_subtitles: remove unneeded ifdef | expand |
Context | Check | Description |
---|---|---|
andriy/ffmpeg-patchwork | success | Make fate finished |
please help to review, so that we can change the subtitle postion, color by force_style. On Mon, Mar 30, 2020 at 06:52:33PM +0800, lance.lmwang@gmail.com wrote: > From: Limin Wang <lance.lmwang@gmail.com> > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com> > --- > doc/filters.texi | 4 ++++ > libavfilter/vf_subtitles.c | 23 +++++++++++++++++++++++ > 2 files changed, 27 insertions(+) > > diff --git a/doc/filters.texi b/doc/filters.texi > index 328e984e92..d26d90d1bb 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -6399,6 +6399,10 @@ Slower shaper using OpenType for substitutions and positioning > @end table > > The default is @code{auto}. > + > +@item force_style > +Override default style or script info parameters of the subtitles. It accepts a > +string containing ASS style format @code{KEY=VALUE} couples separated by ",". > @end table > > @section atadenoise > diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c > index 2f312b0ba8..e3ad8b8d94 100644 > --- a/libavfilter/vf_subtitles.c > +++ b/libavfilter/vf_subtitles.c > @@ -218,6 +218,7 @@ static const AVOption ass_options[] = { > {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, > {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, > {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, > + {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, > {NULL}, > }; > > @@ -234,6 +235,28 @@ static av_cold int init_ass(AVFilterContext *ctx) > /* Initialize fonts */ > ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1); > > + if (ass->force_style) { > + char **list = NULL; > + char *temp = NULL; > + char *ptr = av_strtok(ass->force_style, ",", &temp); > + int i = 0; > + while (ptr) { > + av_dynarray_add(&list, &i, ptr); > + if (!list) { > + ret = AVERROR(ENOMEM); > + return ret; > + } > + ptr = av_strtok(NULL, ",", &temp); > + } > + av_dynarray_add(&list, &i, NULL); > + if (!list) { > + ret = AVERROR(ENOMEM); > + return ret; > + } > + ass_set_style_overrides(ass->library, list); > + av_free(list); > + } > + > ass->track = ass_read_file(ass->library, ass->filename, NULL); > if (!ass->track) { > av_log(ctx, AV_LOG_ERROR, > -- > 2.21.0 >
diff --git a/doc/filters.texi b/doc/filters.texi index 328e984e92..d26d90d1bb 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -6399,6 +6399,10 @@ Slower shaper using OpenType for substitutions and positioning @end table The default is @code{auto}. + +@item force_style +Override default style or script info parameters of the subtitles. It accepts a +string containing ASS style format @code{KEY=VALUE} couples separated by ",". @end table @section atadenoise diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 2f312b0ba8..e3ad8b8d94 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -218,6 +218,7 @@ static const AVOption ass_options[] = { {"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, {"simple", "simple shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_SIMPLE}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, {"complex", "complex shaping", 0, AV_OPT_TYPE_CONST, {.i64 = ASS_SHAPING_COMPLEX}, INT_MIN, INT_MAX, FLAGS, "shaping_mode"}, + {"force_style", "force subtitle style", OFFSET(force_style), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS}, {NULL}, }; @@ -234,6 +235,28 @@ static av_cold int init_ass(AVFilterContext *ctx) /* Initialize fonts */ ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1); + if (ass->force_style) { + char **list = NULL; + char *temp = NULL; + char *ptr = av_strtok(ass->force_style, ",", &temp); + int i = 0; + while (ptr) { + av_dynarray_add(&list, &i, ptr); + if (!list) { + ret = AVERROR(ENOMEM); + return ret; + } + ptr = av_strtok(NULL, ",", &temp); + } + av_dynarray_add(&list, &i, NULL); + if (!list) { + ret = AVERROR(ENOMEM); + return ret; + } + ass_set_style_overrides(ass->library, list); + av_free(list); + } + ass->track = ass_read_file(ass->library, ass->filename, NULL); if (!ass->track) { av_log(ctx, AV_LOG_ERROR,