Hi,
I've updated the patch. Regarding the question, if the key=value has ","
then the token would contain only the value till the special character. The
code doesn't break but it won't work either.

On Wed, Feb 4, 2015 at 7:29 PM, Stefano Sabatini <stefa...@gmail.com> wrote:

> On date Wednesday 2015-02-04 01:30:09 +0530, Eejya Singh encoded:
> > Hi,
> > I've implemented a force_style option in the subtitles filter. Kindly
> find
> > the patch attached.
> >
> > --
> > Eejya Singh,
> > 3rd year undergraduate,
> > Computer Science,
> > BITS Pilani Goa Campus
>
> > From 88014fde69b249d3b1cb8e6bd2f654156ba2b4e7 Mon Sep 17 00:00:00 2001
> > From: Eejya Singh <singh.ee...@gmail.com>
> > Date: Wed, 28 Jan 2015 17:41:42 +0530
>
> > Subject: [PATCH] Adding Force Style option in Subtitles Filter
>
> lavfi/subtitles: add force_style option
>
> >
> > Signed-off-by: Eejya Singh <singh.ee...@gmail.com>
> > ---
> >  doc/filters.texi           | 14 ++++++++++++++
> >  libavfilter/version.h      |  2 +-
> >  libavfilter/vf_subtitles.c | 24 ++++++++++++++++++++++++
> >  3 files changed, 39 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 261fd24..60ef7f4 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -8470,6 +8470,10 @@ useful if not UTF-8.
> >
> >  @item stream_index, si
> >  Set subtitles stream index. @code{subtitles} filter only.
> > +
>
> > +@item force_style
> > +Set desired style for the customization of subtitles.It follows ASS
> style format.
> > +
>
> You should describe the syntax here, otherwise the user will have to
> guesswork.
>
> >  @end table
> >
> >  If the first key is not specified, it is assumed that the first value
> > @@ -8496,6 +8500,16 @@ To render the second subtitles stream from that
> file, use:
> >  subtitles=video.mkv:si=1
> >  @end example
> >
> > +To change the font of subtitles stream from file, use:
> > +@example
> > +subtitles=sub.srt:force_style=FontName=Arial
> > +@end example
> > +
> > +To change the color and formatting of subtitles stream from file, use:
> > +@example
> > +subtitles='sub.srt:force_style=FontName=Arial,PrimaryColour=255'
> > +@end example
> > +
> >  @section super2xsai
> >
> >  Scale the input by 2x and smooth using the Super2xSaI (Scale and
> > diff --git a/libavfilter/version.h b/libavfilter/version.h
> > index 50967f4..7ec374d 100644
> > --- a/libavfilter/version.h
> > +++ b/libavfilter/version.h
> > @@ -31,7 +31,7 @@
> >
> >  #define LIBAVFILTER_VERSION_MAJOR  5
> >  #define LIBAVFILTER_VERSION_MINOR  6
> > -#define LIBAVFILTER_VERSION_MICRO 100
> > +#define LIBAVFILTER_VERSION_MICRO 101
> >
> >  #define LIBAVFILTER_VERSION_INT
> AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> >
>  LIBAVFILTER_VERSION_MINOR, \
> > diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> > index be4c6a5..0fae118 100644
> > --- a/libavfilter/vf_subtitles.c
> > +++ b/libavfilter/vf_subtitles.c
> > @@ -51,6 +51,7 @@ typedef struct {
> >      ASS_Track    *track;
> >      char *filename;
> >      char *charenc;
> > +    char *force_style;
> >      int stream_index;
> >      uint8_t rgba_map[4];
> >      int     pix_step[4];       ///< steps per pixel for each plane of
> the main output
> > @@ -260,6 +261,7 @@ static const AVOption subtitles_options[] = {
> >      {"charenc",      "set input character encoding", OFFSET(charenc),
>     AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
> >      {"stream_index", "set stream index",
>  OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,
>  INT_MAX,  FLAGS},
> >      {"si",           "set stream index",
>  OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,
>  INT_MAX,  FLAGS},
> > +    {"force_style",  "force subtitle style",
>  OFFSET(force_style),  AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN,
> CHAR_MAX, FLAGS},
> >      {NULL},
> >  };
> >
> > @@ -389,6 +391,28 @@ static av_cold int init_subtitles(AVFilterContext
> *ctx)
> >      if (ass->charenc)
> >          av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
> >      ret = avcodec_open2(dec_ctx, dec, &codec_opts);
> > +
>
> You should keep the if ret < 0 check here.
>
> > +    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);
> > +                goto end;
> > +            }
> > +            ptr = av_strtok(NULL, ",", &temp);
> > +        }
> > +        av_dynarray_add(&list, &i, NULL);
> > +        if (!list) {
> > +            ret = AVERROR(ENOMEM);
> > +            goto end;
> > +        }
> > +        ass_set_style_overrides(ass->library, list);
> > +        av_free(list);
> > +    }
>
> Question: in the key=value Ass property couples, can value contain the
> "," special character?
>
> LGTM otherwise.
> --
> FFmpeg = Faithful Fostering Mysterious Prodigious Eretic God
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>



-- 
Eejya Singh,
3rd year undergraduate,
Computer Science,
BITS Pilani Goa Campus
From c0d6197f1936445a23b9eb726de24ed54551c675 Mon Sep 17 00:00:00 2001
From: Eejya Singh <singh.ee...@gmail.com>
Date: Wed, 28 Jan 2015 17:41:42 +0530
Subject: [PATCH] Adding Force Style option in Subtitles Filter

Signed-off-by: Eejya Singh <singh.ee...@gmail.com>
---
 doc/filters.texi           | 14 ++++++++++++++
 libavfilter/version.h      |  2 +-
 libavfilter/vf_subtitles.c | 25 +++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 261fd24..857d281 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8470,6 +8470,10 @@ useful if not UTF-8.
 
 @item stream_index, si
 Set subtitles stream index. @code{subtitles} filter only.
+
+@item force_style
+Set desired style for the customization of subtitles like :- FontSize=15,Italic=-1,Outline=2 etc.It follows ASS style format.
+
 @end table
 
 If the first key is not specified, it is assumed that the first value
@@ -8496,6 +8500,16 @@ To render the second subtitles stream from that file, use:
 subtitles=video.mkv:si=1
 @end example
 
+To change the font of subtitles stream from file, use:
+@example
+subtitles=sub.srt:force_style=FontName=Arial
+@end example
+
+To change the color and formatting of subtitles stream from file, use:
+@example
+subtitles='sub.srt:force_style=FontName=Arial,PrimaryColour=255'
+@end example
+
 @section super2xsai
 
 Scale the input by 2x and smooth using the Super2xSaI (Scale and
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 50967f4..7ec374d 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFILTER_VERSION_MAJOR  5
 #define LIBAVFILTER_VERSION_MINOR  6
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index be4c6a5..50eab9b 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -51,6 +51,7 @@ typedef struct {
     ASS_Track    *track;
     char *filename;
     char *charenc;
+    char *force_style;
     int stream_index;
     uint8_t rgba_map[4];
     int     pix_step[4];       ///< steps per pixel for each plane of the main output
@@ -260,6 +261,7 @@ static const AVOption subtitles_options[] = {
     {"charenc",      "set input character encoding", OFFSET(charenc),      AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
     {"stream_index", "set stream index",             OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,       INT_MAX,  FLAGS},
     {"si",           "set stream index",             OFFSET(stream_index), AV_OPT_TYPE_INT,    { .i64 = -1 }, -1,       INT_MAX,  FLAGS},
+    {"force_style",  "force subtitle style",         OFFSET(force_style),  AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS},
     {NULL},
 };
 
@@ -389,9 +391,32 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
     if (ass->charenc)
         av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
     ret = avcodec_open2(dec_ctx, dec, &codec_opts);
+
     if (ret < 0)
         goto end;
 
+    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);
+                goto end;
+            }
+            ptr = av_strtok(NULL, ",", &temp);
+        }
+        av_dynarray_add(&list, &i, NULL);
+        if (!list) {
+            ret = AVERROR(ENOMEM);
+            goto end;
+        }
+        ass_set_style_overrides(ass->library, list);
+        av_free(list);
+    }
+
     /* Decode subtitles and push them into the renderer (libass) */
     if (dec_ctx->subtitle_header)
         ass_process_codec_private(ass->track,
-- 
1.9.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to