]> git.sesse.net Git - ffmpeg/commitdiff
lavfi/drawtext: ignore final LF of textfile.
authorNicolas George <george@nsup.org>
Mon, 30 Nov 2020 18:28:36 +0000 (19:28 +0100)
committerNicolas George <george@nsup.org>
Wed, 17 Feb 2021 10:53:51 +0000 (11:53 +0100)
A standard text file ends with a final LF.
Without this change, it is interpreted as an empty final line,
and visible with the box option.
The current behavior can be achieved by actually having
an empty line at the end of the file.

Fix trac ticket #7948.

libavfilter/vf_drawtext.c

index abe1ca6c35cef97fd5e503531c87d348cee67c2c..7b1000e5bdbcafb33d1c03f2393a8f96a55ecad1 100644 (file)
@@ -568,6 +568,11 @@ static int load_font(AVFilterContext *ctx)
     return err;
 }
 
+static inline int is_newline(uint32_t c)
+{
+    return c == '\n' || c == '\r' || c == '\f' || c == '\v';
+}
+
 static int load_textfile(AVFilterContext *ctx)
 {
     DrawTextContext *s = ctx->priv;
@@ -583,6 +588,8 @@ static int load_textfile(AVFilterContext *ctx)
         return err;
     }
 
+    if (textbuf_size > 0 && is_newline(textbuf[textbuf_size - 1]))
+        textbuf_size--;
     if (textbuf_size > SIZE_MAX - 1 || !(tmp = av_realloc(s->text, textbuf_size + 1))) {
         av_file_unmap(textbuf, textbuf_size);
         return AVERROR(ENOMEM);
@@ -595,11 +602,6 @@ static int load_textfile(AVFilterContext *ctx)
     return 0;
 }
 
-static inline int is_newline(uint32_t c)
-{
-    return c == '\n' || c == '\r' || c == '\f' || c == '\v';
-}
-
 #if CONFIG_LIBFRIBIDI
 static int shape_text(AVFilterContext *ctx)
 {